Control structures Quiz

Pre-Quiz

Q1 – Dene what kind of language is python ?




Q2 – Object Oriented Programming is possible in Python. State whether ‘True’ or ‘False’




Q3 – Identify the correct operator for power(x^y).




Q4 – Identify which one of these is oor division.




Q5 – Mathematical operations can be performed on a string. State whether ‘True’ or ‘False’.





Practice Session


Q1 – Fill in the simple for loop to print even numbers from -10 to 10, excluding 0.
for i in range( ________ ):
if( ________ ):
continue
print(i)

-10,11,2

i == 0


Q2 – Fill in the simple while loop to print numbers from -10 until 0 (0 inclusive).
num=-10
_____ (num ____  0):
print(num)
num=num+1.

while

<=



Post Quiz


Q1 – Analyse and nd which of the following loops correctly computes 1/2 + 2/3 + 3/4 + … + 99/100.
A:
sum = 0
for i in range(1, 99):
  sum += i / (i + 1)
print(“Sum is”, sum)
B:
sum = 0
for i in range(1, 100):
  sum += i / (i + 1)
print(“Sum is”, sum)
C:
sum = 0
for i in range(1.0, 99.0):
  sum += i / (i + 1)
print(“Sum is”, sum)
D:
sum = 0
for i in range(1.0, 100.0):
  sum += i / (i + 1)
print(“Sum is”, sum)




Q2 – Evaluate the given code and tell which single line of code can be used to replace this sample code?
nums = [1,2,3,4,5,6,7,8,9]
x = 0
for n in nums:
  x = x + n
print(x)




Q3 – Select the choices that should not appear in the place of EXP – given : for k in EXP:




Q4 – Which statement best describes the behavior of the following expression?
x != 0 and y % x != 0




Q5 – Analyse and predict the output for the following.
isCorrect = False
print(“Correct” if isCorrect else “Incorrect”)





Check Your Understanding


Q1 – Arrange the following code

n=input()

sum=0

for i in range(0,n,1)

sum=sum+i

print(sum)


Q2 – Find the missing part of the following code. To print the even numbers between 0 to n
__ =input()
for i in range( __ ,n, __ )
print( __ )

n

0

2

i


Q3 – The else block can be included along with while loop




Q4 – Match the following

x=bool(0)
y=bool(1)
if x:
  print(x)
else:
  print(y)

for i in range(1,2,2):
  print(i)

n=2
for i in range(0,n,1):
  if bool(i):
   print(i)

True

1

1


Q5 –

Tab space

indentation is used for the statements under loops


Leave a Comment

Your email address will not be published. Required fields are marked *