U VX 74 MDL 10311
U VX 74 MDL 10311
v)
a = [0, 1, 2, 3]
for a[-1] in a:
print(a[-1],end = ',' )
c) Write a function that returns n Fibonacci numbers 6
(example: for n = 5 , output : 0 1 1 2 3 )
test.py:
def increment(n):
return n+1
illustrate different ways to import and use the increment function in a python program
d) Explain with examples the syntax for the following functions in the tkinter module : 4
i) Label() ii) Entry()
4 a) i) Write a program using List comprehension and selection control to check if a given 3+2+1
. number is prime or not.
b)
x = [43, 32]
print(len(''.join(list(map(str, x)))))
b) Write a user defined function to mimic filter and use it to remove numbers divisible by 6
3 from a given list of numbers.
numbers = [1,2,3,4,5,6]
output: [1,2,4,5]
c) What is the output of the following code? 4
class myRange:
def __init__(self,n):
self.limit = n
def __iter__(self):
self.i = 0
return self
def __next__(self):
self.i += 1
return self.i-1
r = myRange(5)
t = iter(r)
print(next(t))
print(next(t))
u = iter(r)
print(next(u))
print(next(t))
d) i) Explain with example any 3 commands used in debugging 3+1
ii) Write the command used to open the python debugger from the command
prompt/terminal
5 a) Create a class Queue that implements the working of a queuing system. The class 8
will have attributes such as limit: maximum number of people in the queue (consider
the limit as 10) and people_queue: which is a list on names in a queue.
c) Given a list k = [1,4,0,5,3] , write a program that calculates the reciprocal of every 6
element in the list and store it in another list called reciprocal. Incorporate exception
handling to handle the division by zero error when calculating the reciprocal of 0
(zero)