Monday Test-2

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Monday Test-2

Fundamentals of Python Programming


Note: Attempt any 5 Questions
Q-1: What is output of the following codes :

(A)

var = 10
for i in range(10):
for j in range(2, 10, 1):
if var % 2 == 0:
continue
var += 1
var+=1
else:
var+=1
print(var)

(B)

for num in range(2,-5,-1):


print(num, end=", ")

(C)

numbers = [10, 20]


items = ["Chair", "Table"]

for x in numbers:
for y in items:
print(x, y)

(D )

x = 0
while (x < 100):
x+=2
print(x)
a x = 0
a = 5
b = 5
if a > 0:
if b < 0:
x = x + 5
elif a > 5:
x = x + 4
else:
x = x + 3
else:
x = x + 2
print(x)
print(x, y)
(E)

x = 0
for i in range(10):
for j in range(-1, -10, -1):
x += 1
print(x)

Q2 : Find and correct the errors from following programs:


1. if (a>b)
print(“Hello)
2. t = (1, 2,3):
print(3 * t)
3. i=1
while(i=<10)
print(i)
4. Write the output of the following program:
a = True
b = False
c = False
if a and b and c:
print ("Hello")
else:
print ("Hi")
5. Write the output of the following program:
x = ['ab', 'cd']
for i in x:
i.upper()
print(x)
Q3: Fill the Answer in Question mark:
List= [1,2,3,4,5]
print(list[0:3])
output: ?
List.append(5)
print(List)
output: ?
Del List[3]
print(len(List))
output: ?
print( 3 in List)
output: ?
print(List[-1:-4])
output: ?
Q-4 Fill the Answer in Question mark:
Dictionary = {1: "Harpal", 2:"Gurpreet", 3: "Gurjeet", 4:"Harpreet "}
print( Dictionary[2])
output: ?
Dictionary.pop(3)
print(Dictionary)
output: ?
Dictionary[0]="Gurmeet"
print(Dictionary[2][-1])
output: ?
Dictionary.popitem()
print(Dictionary[0])
output: ?
Dictionary.clear()
print(Dictionary)
output: ?

Q5: Write a program to calculate the factorial of a number input by the user

Q6: Write a program to print the Fibonacci series

Q7: Write in brief about Tuple in python. Write operations with suitable examples.

You might also like