CH-1 Assignment
CH-1 Assignment
20. How many times will Python execute the code inside the following while loop? You should answer the question
without using the interpreter! Justify your answers.
i=0
while i < 0 and i > 2 :
print “Hello ...”
i = i+1
25. What will be the output of the following python expression? print(2**3**2)
26. Observe the given dictionary:
d_std={“Roll_No”:53,”Name”:’Ajay Patel’}
d_marks={“Physics”:84,”Chemistry”:85}
Which of the following statement will combine both dictionaries?
a) d_std + d_marks
b) d_std.merge(d_marks)
c) d_std.add(d_marks)
d) d_std.update(d_marks)
27. What will be the output for the following expression:
not ((False and True or True) and True)
True or not True and False
28. Select the correct output of the following python code:
str=”My program is program for you”
t = str.split(“program”)
print(t)
a) [‘My ‘, ‘ is ‘, ‘ for you’] b) [‘My ‘, ‘ for you’] c) [‘My’,’ is’] d) [‘My’]
29. What will be the output of following expression in python?
print ( round (100.0 / 4 + (3 + 2.55) , 1 ) )
30. What will be the data type of p, if p=(15)?
31. What will the following expression be evaluated to in Python?
print(25//4 +3**1**2*2)
32. Given is a Python string declaration:
message='FirstPreBoardExam@2022-23'
Write the output of: print(message[ : : -3].upper())
33. Predict the output of the following code:
dt=["P",10,"Q",30,"R",50]
t=0
a=""
ad=0
for i in range(1,6,2):
t = t + i
a = a + dt [i-1] + "@"
ad = ad + dt[i]
print (t, ad, a)
s="ComputerScience23"
n = len(s)
m=""
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'):
m = m +s[i].upper()
elif (s[i]>=’n’ and s[i]<=’z’):
m = m +s[i-1]
elif (s[i].isupper()):
m=m+s[i].lower()
else:
m=m+’#’
print(m)
35. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in
the code.
Num=int(rawinput("Number:"))
sum=0
for i in range(10,Num,3)
sum+=1
if i%2=0:
print(i*2)
else:
print(i*3)
print (Sum)
36. Vivek has written a code to input a number and check whether it is even or odd number. His code is
having errors. Rewrite the correct code and underline the corrections made.
Def checkNumber(N):
status = N%2
return
#main-code
num=int( input(“ Enter a number to check :"))
k=checkNumber(num)
if k = 0:
print(“This is EVEN number”)
else
print(“This is ODD number”)
37. Sameer has written a python function to compute the reverse of a number. He has however committed a
few errors in his code. Rewrite the code after removing errors also underline the corrections made.
define reverse(num):
rev = 0
While num > 0:
rem == num %10
rev = rev*10 + rem
num = num/10
return rev
print(reverse(1234))
38. Suppose a tuple T is declared as T = (10, 12, 43, 39), which of the following is incorrect?