100% found this document useful (1 vote)
115 views

AS_CBSE_VIII_Computer Studies_Ch 7_Python_Lists Functions and Modules (1)

Uploaded by

nisha.kawale
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
115 views

AS_CBSE_VIII_Computer Studies_Ch 7_Python_Lists Functions and Modules (1)

Uploaded by

nisha.kawale
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

7.

Python - Lists Functions and


Modules
Q.1. Select the correct output for the given Python code. [An
]
a. flowers=["rose","jasmine","lily","mogra"]

print(flowers[3:])

i. [“lily”] ii. [“mogra”]

iii. [“lily”,”mogra”] iv. [“jasmine”,”lily”]

b. colours=["green","blue","red","purple"]

print(colours[1])

i. green ii. blue

iii. red iv. purple

c. Based on the given code, which colour will be removed


from the list?

colours=["green","blue","red","purple"]

colours.pop()

i. red ii. green

iii. purple iv. blue

d. num=84.5368

rounded_num=round(num,1)

print(rounded_num)

i. 84.5 ii. 84.53

iii. 84.536 iv. 8.45368

Python – Lists, Functions and Modules Pg no.


7. Python - Lists Functions and
Modules

e import random

def select_num():

return random.randint(1,3)

select_num_output=select_num()

print(select_num_output)

i. Prints number 1
ii. Prints number 2 only
only

iii. Prints number 3 iv. Prints any number


only between 1 and 3

Q.2 Answer the following questions.

a. Describe the type of data structure in the examples [R]


given below.

i.

Ans. It is a list. A list is a data structure that represents


an ordered collection of elements. It is denoted by
square brackets.

ii.

Ans. It is a tuple. A tuple is similar to a list but


immutable, meaning its contents cannot be
modified once created. Tuples are denoted by
parentheses (( )) or without any brackets.

iii.

Ans. It is a dictionary. A dictionary is an unordered


collection of key-value pairs. It is denoted by curly
braces ({ }) and consists of key-value pairs

Python – Lists, Functions and Modules Pg no.


7. Python - Lists Functions and
Modules
separated by commas.

iv.

Ans. It is a set. A set is an unordered collection of


unique elements. It is denoted by curly braces
({ }).

b. What is the difference between the append() and [An


insert() method of a list in Python? ]

Ans  The append() method allows you to add an


. element to the end of a list.
 The insert() method allows you to add an
element at a specific index in the list.

c. Explain the concept of slicing with respect to lists in [R]


Python.

Ans  Slicing allows you to specify a start and end


. index, and it returns a new list containing the
selected elements.
 When you specify a start index, the element
at that index is included in the slice. In other
words, the selected range includes the
element at the start index.
 When you specify an end index, the element
at that index is not included in the slice. The
selected range ends just before the element
at the end index.

d. What is the difference between parameters and


arguments while using functions in Python?

Ans Parameters are the variables listed in the


. function definition. They act as placeholders for
the values passed to the function.

Python – Lists, Functions and Modules Pg no.


7. Python - Lists Functions and
Modules
Example

Arguments are the actual values that are passed


to the function when it is called. These values
are assigned to the corresponding parameters in
the function definition.

e. Define a function that simulates the throwing of


multiple dice. The function should accept an argument
for the number of dice to be rolled. It should generate a
random number between 1 and 6 for each dice, store
the outcomes in a list and return the list. The program
should display the result list after the function is called.

Ans
.

Python – Lists, Functions and Modules Pg no.


7. Python - Lists Functions and
Modules

Q.3 Observe the Python code given below and write the [An
correct output for each code. ]

a. student_name=['Navya','Amit']

length=len(student_name)

print("The length is:", length)

Ans The length is: 2


.

b. import math

print(math.pow(2,4))

Ans 16.0
.

c. num=[5,10,15,20]

value=type(num)

print("The type is:", value)

Ans The type is: <class 'list'>


.

Q.4 Identify the errors in the given program and rewrite


the code to get the given output.
Code

Python – Lists, Functions and Modules Pg no.


7. Python - Lists Functions and
Modules
Enter an integer 100

Square root of 100 is 10

Lab Activity

Q.1 Write a function to identify the largest item from a list of


integers. The function should take the list as an argument.
Test the function by calling in the program.

Q.2 Using a list of integers modules, write a program in Python to


accept two numbers from the user and find the greatest
common divisor of the two numbers.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Python – Lists, Functions and Modules Pg no.

You might also like