0% found this document useful (0 votes)
54 views

Python Revision Tour Functions HW Worksheet 2 12E

1. The document provides a worksheet with 10 questions on Python functions, data types, operators, and control flow. Some questions ask the student to identify code elements, explain concepts, or predict output. 2. Other questions ask the student to help complete code snippets, such as filling in missing lines of a Fibonacci series generator. 3. The final two questions ask the student to write Python programs, one to calculate a series using a function and the other to find and display palindrome and perfect numbers from lists using defined functions.

Uploaded by

Srijit Saha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Python Revision Tour Functions HW Worksheet 2 12E

1. The document provides a worksheet with 10 questions on Python functions, data types, operators, and control flow. Some questions ask the student to identify code elements, explain concepts, or predict output. 2. Other questions ask the student to help complete code snippets, such as filling in missing lines of a Fibonacci series generator. 3. The final two questions ask the student to write Python programs, one to calculate a series using a function and the other to find and display palindrome and perfect numbers from lists using defined functions.

Uploaded by

Srijit Saha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PYTHON REVISION TOUR

WORKING WITH FUNCTIONS


H/W WORKSHEET
1. Identify the different tokens of given Python code:
for i in range(1,10):
if i % 2 == 0:
print(i % 2)
2. State the name of immutable types of Python. Explain their immutability with the
help of an example.
3. What are the different division operators of Python? Differentiate with examples.
4. Name the following:
a) This function of string class returns -1 if the given argument is not found in
the string.
b) This function when used with list deletes the last element and when used with
dictionary deletes the specified element only.
c) This function helps to change a tuple into list.
d) This function of dictionary changes the original dictionary with the new
key,value pair.
e) This function can be used to find the no. of elements present in any string, list
or tuple.
5. Predict the output:
a) for name in [‘james’, ‘rajesh’, ‘leonard’, ‘tom’, ‘sam’]:
print(name)
if name[0] == ‘t’:
break
else:
print(‘Finished traversing’)
b) x = [1,2,3]
cnt = 0
while cnt < len(x):
print(x[cnt] * ‘%’)
for y in x:
print(y* ‘*’)
cnt+=1
c) x =’one’
y = ‘two’
c=0
while c < len(x):
print(x[c],’\t’, y[c])
c+=1
6. Riya wrote a program to print the Fibonacci series. But some lines had gone
missing. Help her to execute the program.
N = int(input(“how many terms? “))

1|Page
CS(083)-CLASS XII
n1, n2 = 0,1
count = 0
if n < = 0:
print(“Please enter positive number”)
elif _____ #1:
print(‘Fibonacci series upto”, n, “:”)
print(_____ #2)
else:
print(“Fibonacci sequence: “)
while count < n:
print(n1)
n3 = ______ #3
n1 = n2
n2 = ______ #4
count = _____ + 1 #5
7. Data types are the classification or categorization of data item. It represents the
kind of value that tells what operations can be performed on a particular data.
Since everything is an object in Python programming, data types are actually
classes, and variables are instance ( object ) of these classes.
Python has following built -in data types : Numeric, Sequence type, Boolean , set,
mapping.
1. What do you mean by sequence data types?
2. List the types of numeric data type,
3. How many values are there in Boolean data type?
4. What is the use of None?
5. Write the output of:
>>>type(“Apple”)
>>>list(“Apple”)
8. Write a python program to find the sum of the following series :
1 + 12 + 123 + 1234 + … upto N terms, using void function repeat(N)
9. Write a python program to find and display all the palindrome nos. from a tuple
elements.
10. Write a python program to count and display all the perfect nos. from a list of
elements using void function def LPerfect(L)
[Hint: Perfect no. – A perfect no. is a no. which is the sum of all its factors except
the no. itself. E.g. – 6 is a perfect no. Factors = 1,2,3. Sum of factors = 1 + 2 + 3 =
6]
Sample Input: L = [10,6,2,21,14,28]
Sample Output: Perfect numbers are = 6,28
Count = 2

2|Page
CS(083)-CLASS XII

You might also like