0% found this document useful (0 votes)
521 views11 pages

WORKSHEET - Conditional and Looping Constructs

Worksheet cs

Uploaded by

shab050465
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
521 views11 pages

WORKSHEET - Conditional and Looping Constructs

Worksheet cs

Uploaded by

shab050465
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

TERM -1 MCQ PRACTICE QUESTIONS

Worksheet for Conditional and Looping Constructs

1. Observe the following code carefully and find which statement will never get executed in
the code?
t=1 #statement1
while(t<=15): #statement2
if t>13: #statement3
print(“Something”) #statement4
else: #statement5
print(“Pass”) #statement6
t+=3 #statement7
(i) statement 1 (ii) statement 2 (iii) statement 3 (iv) statement 4
2. Write the value of sum1 after execution of the following WHILE loop?
i=1
sum1 = 0
while i<10:
sum1 =sum1+ i
i =i+2
(i) 24 (ii) 25 (iii) 26 (iv) 27
3. Give the output.
for i in range(1,10,3):
print ( i, sep = ”-”, end = ”*” )
(i) 1-4-7* (ii) 1-4-7-10* (iii) 1*4*7* (iv) 1*4*7*10
4. Give the output.
m = 16
m = m+1
if m<15:
print(m)
else:
print(m+15)
(i) 32 (ii) 16 (iii) 17 (iv) 31
5. Which one of the following is a valid Python if statement.
a) if a>=2 : b) if (a >= 2) c) if (a => 22): d) if a >= 22
6. What keyword would you use to add an alternative condition to an if statement?
a) else if b) elseif c) elif d) None of the above
7. What is the output of the given below program?
if 1 + 3 == 7:
print("Hello")
else:
print("Know Program")
a) Hello b) Know Program
c) Compiled Successfully, No Output d) Error
8. What is the output of the given below program?
A,b = True,False
if (a and b):
print("Hello")
else:
print("Know Program")
a) Hello b) Know Program
c) Compiled Successfully, No Output. d) NameError
9. Can we write if/else into one line in python?
a) Yes b) No c) if/else not used d) None of the above
10. If statement inside if statement is called Nested if statements.
a) True b) False
11. Print(bool(True and True or False)) evaluates to ____.
a) False b) True c) Error d) None of the above
12. Which of following is not a decision-making statement?
a) if-elif statement b) for statement c) if -else statement d) if statement
13. Sara wants to make a fun program, if user enters any number a “Good” or “funny” message
will appear . She is confused that which is the most suitable control to be used to make
such program. Help her to choose correct option.
a) if b) if else c) if elif d) Nested if else
14. If the condition is ______, the statements of if block will be executed otherwise the
statements in the _____ block will be executed.
a) False, true b) true, else c) both options are true d) Can‟t say
15. Which statement will check if a is equal to b?
a) if a = b: b) if a == b: c) if a === c: d) if a == b
16. In a Python program, a control structure:
a) Defines program-specific data structures
b) Directs the order of execution of the statements in the program
c) Dictates what happens before the program starts and after it terminates
d) None of the above
17. State which of the following statement are true.
a) If, elif, else are not compound statement. b) Else if can be used in python.
c) Indentation while working with blocks is not necessary in python.
d) A pass statement is a null operation; it does nothing.
18. In Python, ________ defines a block of statements.
a) Block b) loop c) indentation d) { }
19. The order of statement execution in the form of top to bottom is known as construct.
a) alternate b) sequence c) flow of data d) flow chart
20. Symbol used to end the if statement.
a) ; b) - c) _ d) :
21. The _____ statement forms the selection construct in Python.
a) If else if b. if c. For ; d. for
22. An ______ statement has less number of conditional checks than two successive ifs.
a) If else if b. if elif c. if-else d. none
23. An empty /null statement in Python is ______.
a) pass b. none c. null d. none
24. What is the logical expression for the following, Either A is greater than B or A is less
than C.
a) A>B or A<C b) A>B and A<C
c) A>Band C d) A>B or C
25. Name is rohit and age between 18 and 35.
a) name==rohit and age >=18 and age<=35 b) name==rohit and age >=18 or age<=35
c) name==rohit or age >=18 and age<=35 d) none
26. Does python have switch case statement?
a) True b) False
c) Python has switch statement but we cannot use it d) None of the above
27. Checking multiple conditions in python requires……….. statement.
a) if b) if……. elif c) switch d) None of these
28. What is another word for „iteration‟?
a) Selection b) Assignment c) Sequencing d) Repetition
29. elif can be considered to be abbreviation of.
a) nested if b) if..else c) else if d) if..elif
30. The condition in the if statement should be in the form of.
a) Arithmetic or Relational expression b) Arithmetic or Logical expression
c) Relational or Logical expression d) Arithmetic
31. What is output of: 35 == 35.0
a) False b) True c) 33 d) None of the above
32. Which of the following is invalid?
a) _a = 1 b) __a = 1 c) __str__ = 1 d) none of the mentioned
33. If expression. The expression can be of which type?
a) True b) Any number c) Any string d) All of the mentioned
34. Find the output of the given Python program?
a, b, c = 1, 3, 5
if a + b + c:
print("Hello")
else:
print("Know Program")
a) Hello b) Know Program
c) Compiled Successfully, No Output. d) Error
35. Which of the following is a valid keyword?
a) IF b) if c) If d) none of these
36. Which of the following is not a loop statement in python?
a) while b) do-while c) for d) All of these
37. Statements are the ____ given to computer to perform any task.
a) instructions b) condition c) iterate d) none of these
38. if with ____ is used where multiple chain of condition is to be checked.
a) else b) if c) elif d) none of these
39. If statements inside if statements, this is called ______ statements.
a) looping b) nested if c) elif d) if…else
40. Write the output of the following code:
s="blog"
for i in range(-1,-len(s),-1):
print(s[i],end="$")
a. g$o$l$b$ b. g$o$l$ c. Error d. None of the above
41. In Python, Control statements are used for:
a. Controls what to do before execution and after termination of program
b. Controls the order of execution of statements in program
c. Controls input and output of program d. Controls the data types of Python program
42. Which of the following if statement will not execute?
a. if a==10: print(“10”) b. if a==10: print(“10”)
c. if a==10: print(“10”) d. if a==10: print(“10”)
43. What signifies the end of block of if statement?
a. } b. : c. A line less indented than previous line d. A comment
44. Which one of the following is valid if statement?
a. if x>=10: b. if (x>=10) c. if(x=>10): d. if x<=10
45. Which of the following is not decision making statement?
a. if-else b. if-elif c. if d. for
46. What will be the output of following Python code?
if True:
print(“Welcome”)
else:
print(“Bye”)
a. Welcome b. Bye c. Welcome Bye d. No output
47. What will be the output of following Python code?
if 20>=20:
print(“Hello”)
else:
print(“Sayonara”)
print(“Welcome”)
a. Hello b. Sayonara c. Hello d. Sayonara
Welcome Welcome
48. Which keyword is used to add alternative condition for if statement?
a. else b. else if c. elif d. elsif
49. What will be the output of following Python code?
num = 5
if num>4 or num<10 and num==8:
print("Well done")
else:
print("Better Luck next time")
a. Well done b. Better Luck next time
c. Well done Better Luck next time d. None of the above
50. What will be the output of following code, if the user enter 5 for the variable num?
num = int(input('Enter number '))
if num==2:
print("Yes")
elif num>=5:
print("Can't Say")
else:
print("No")
a. Yes b. No c. Can‟t Say d. Nothing will be printed
51. Observe the following given code(A) and code(B) and answer the given question:
CODE(A) CODE(B)
a=2 a=2
if a==1: if a==1:
print(“One”) print(“One”)
elif a==2: if a==2:
print(“Two”) print(“Two”)
elif a==3: if a==3:
print(“Three”) print(“Three”)
else: else:
print(“Not valid option”) print(“Not valid option”)
Out of Code(A) and Code(B), which of the code will take less time to execute the code?
a. Code(A) b. Code(B)
c. Both Code(A) and (B) will take same amount of time d. None of the above.
52. Find the output of following Python code?
X = 10
if X:
print(X)
else:
print(X+10)
a. 10 b. 20 c. No output d. Error
53. If within another if is known as,
a. Multiple if b. Chaining if c. Nested if d. Compound if
54. Which of the following conditional statement will check, if the Grade is greater than or
equal to 2 and Salary between 50000 to 90000?
a. Grade=1 and Salary>=50000 and Salary<=90000
b. Grade==1 and Salary>=50000 and <=90000
c. Grade==1 and Salary>=50000 and Salary<=90000
d. Grade==1 or Salary>=50000 and Salary<=90000
55. Which of the following will check whether the value of a is equals to b?
a. a=b b. a equals b c. a is b d. a==b
56. Ravi is creating a program to check whether the entered number (num) is even or odd. He
is not getting the correct condition, help Ravi in identifying the correct condition for this.
a. if num//2==0: b. if num%2=0: c. if num%2==0: d. if num/2==0
57. Which of the following will check the correct leap year(Y) condition?
a. (Y%100!=0 or Y%400)==0 and Y%4==0 b. (Y%400==0) or (Y%100!=0 and Y%4==0)
c. (Y%400==0) and (Y%100!=0 and Y%4==0) d. (Y%4==0) or (Y%100==0 and Y%400==0)
58. Namrata, wants to write a program whether she can check if Age entered is 18 or above
message “You can Vote” to appear otherwise “You cannot Vote” to appear. She is
confused which control statement she should use. Help Namrata to find the best option
out of following.
a. if b. if-elif c. if-else d. nested if
59. What will be the output of following Python code?
if 0:
print("Not Again")
else:
print("As Expected")
a. Not Again b. Not Again As Expected
c. As Expected d. Nothing will be printed
60. What will be the output of following Python code?
if 2==2:
if 5>6:
print("Inside If")
else:
print("Inside Else")
print("Done!")
a. Inside if b. Inside Else Done! c. Inside If d. Inside Else
Done! Done!
61. range(2,21) will generate values in the range of _____.
a. 2 to 21 b. 2 to 20 c. 1 to 20 d. 2 to 22
62. range(40) will generate values in the range of _____.
a. 0 to 39 b. 0 to 40 c. 1 to 39 d. 1 to 40
63. range(1,20,-1) will generate values in the range of _____.
a. 20 to 1 b. 20 to 2 c. 20 to 0 d. None of the following
64. range(30,0,-1) will generate values in the range of ___.
a. 30 to 0 b. 30 to 1 c. 29 to 0 d. 20 to 1
65. range(10,100,10) will generate values:
a. 10 to 100. b. 10 to 100 with interval of 10
c. 10 to 99 with interval of 10 d. 10 to 99
66. How many times “Hello” will be printed?
for i in range(1,21,5):
print("Hello")
a. 5 b. 6 c. 4 d. 3
67. How many times “Hello” will be printed?
for i in range(1,21):
if i%5==0:
continue
print("Hello")
a. 14 b. 15 c. 16 d. 17
68. Which of the following argument must be passed to for loop?
a. Initial Value b. Terminating condition c. Stepping/Hopping d. Indexing
69. Which keyword is used to terminate for loop for certain condition?
a. break b. continue c. return d. exit
70. Which keyword is used to skip the loop statement and resume the loop with next value?
a. break b. continue c. return d. exit
71. What is the output of following Python code?
for i in range(0,20,2):
print(i, end=' ')
a. 0 2 4 6 8 10 12 14 16 18 b. 0 2 4 6 8 10 12 14 16 18 20
c. 0 2 4 6 8 10 12 14 16 18 20 22 d. 1 3 5 7 9 11 13 15 17 19
72. Which of the following statement is true with respect to for loop of Python?
a. We use for loop to iterate until a particular condition is met
b. We can use for loop to iterate over any data type
c. We can use for loop to iterate over string, list, tuple and dictionary
d. For loop is by default infinite loop
73. To iterate 10 times, which of the following for range() will work?
a. range(1,10) b. range(0,9) c. range(10) d. range(1,10,2)
74. What will be the output of following Python code?
for i in range(1,10,3):
print('#'*i,end='*')
a. #*####*#######* b. #######*
c. #*###*######* d. #*####*####*####*
75. Find out the output of following Python code. msg=”India”
for i in msg:
print(i,end=‟*‟)
a. India* b. I* n* d* i* a* c. I*n*d*i*a* d. None of the following
76. What will be the value of P after execution of following Python code?
P=10
Q=0
for i in range(1,10,2):
P+=Q
Q+=i
print(P)
a. 20 b. 30 c. 40 d. 50
77. What will be the output of following Python code?
num=420
for i in num:
print(i)
a. 420 b. 4 2 0 c. Error d. None of the following
78. How many times „Hello‟ will be printed?
for i in range(0):
print('Hello')
a. 1 b. 0 c. Error in code d. None of the above
79. What will be the output of following Python code?
Prices=[100,200,250,150,325,475]
sum=0
for i in Prices:
sum+=i
print(sum)
a. 6 b. 1400 c. 1500 d. 1550
80. How many times this loop will run?
for i in range(-10):
print(i)

a. 0 b. 1 c. 10 d. 9
81.

82. Which statement is used for the condition a loop is to be repeated 30 times?
(a) for i in range (0, 30) : (b) for i in range (0, 30, +1):
(c) for i in range (1, 31, 1): (d) All of these
83. What is the output of following code?
mul=3
value=10
for i in range (1, 6, 2):
if (value% mul==0):
print(value*mul)
else:
print(value+mul)
84. What is the output of following code?
n=4
f=1
while (n>0):
f=f*n
n=n−1
print(f)
(a) 24 (b) 120 (c) 10 (d) Error
85. What is the output of following code?
n = 156
f=0
x=0
while (n > 3) :
r = n% 100
if (r % 2 ! = 0):
f+=r
else :
x+=r
n/=100
print(f − x)
(a) 56 (b) – 56 (c) 55 (d) 155
86. Identify the output of following code.
a=3
while (a<12) :
print(a, end= „ ‟)
a=a+2
(a) 3 4 5 6 7 8 9 10 11 12 (b) 3 4 5 6 7 8 9 10 11
(c) 3 5 7 9 11 (d) 5 7 9 11
87. What is the output of following code?
x=1
for i in range (1, 7, 2) :
x+=i+2
print(x)
(a) 16 (b) 9 (c) 25 (d) Error
88. What will be the output of the following Python code snippet?
x = „ARIHANT‟
for i in range(len(x)):
x[i].lower()
print(x)
(a) ARIHANT (b) arihant (c) Arihant (d) Error
89. Give the output. Num = 6
Num = Num + 1
if Num > 5:
print(Num)
else:
print(Num+5)
90. Give the output.
N = 20
N=N+1
if N<21:
print(N+10)
else:
print(N+15)
91. Give the output.
Age, Relatxation = 24, 6
ModiAge = Age - Relatxation
if ModiAge < 18:
print(“Eligible”)

else:
print(“Not eligible”)
92. Give the output.
for i in 1,3,10,15:
print(i)
93. What will be displayed after the execution of the following code?
z=4
while z<=8:
print(z+3, „ „ )
z=z+2
94. Kritiks write a Python program which iterates the integers from 1 to 50. For multiples
of three print "Fizz" instead of the number and for the multiples of five print "Buzz".
For numbers which are multiples of both three and five print "FizzBuzz". Help her to
complete the following code: .
for fizzbuzz in range( ): # Statement 1
if : #statement2
print("fizzbuzz")
elif fizzbuzz%3==0:
print("fizz")
elif fizzbuzz%5==0:
print("buzz")
print(fizzbuzz)
(i) Which of the following command id used to generate the integer from 1 to 50 in
statement 1?
a. range(1,51) b. range(50) c. range(1,50) d. range(52)
(ii) Which of the following command used to check the number is divisible by 3 and 5 in
statement 2
a. fizzbuzz % 3 == 0 and fizzbuzz % 5 == 0 b. fizzbuzz % 3 == 0 or fizzbuzz % 5 == 0
c. fizzbuzz / 3 == 0 and fizzbuzz % 5 == 0 d. fizzbuzz// 3 == 0 and fizzbuzz//5 == 0
(iii) How many times this loop will be executed.
93. What will be displayed after the execution of the following code?
s=0
for i in range(1,10):
s=s+i
print(i,s,sep=”,”)
94. What will be the values of variables sum after execution of the following loop?
v=6
sum=0
while v>3:
sum+=v;
v-=2
95. Observe the following code carefully and find which statement will never get executed in
the code:
counter=1 #statement1
while counter<=15: #statement2
if counter<15: #statement3
print(“Jump”) #statement4
else: #statement5
print(“Stop”) #statement6
counter+=4 #statement7
96. Write the value that will be stored in variable p after execution of following code. How
many times will the loop execute?
y, x, p = 3,5,0
while y > 0:
p = p + x y = y-1
97. What will be the output displayed, when the following code is executed?
a=5
b=2
while a < 20:
a=a+b
b=a-b
print(a,end=” “)
98.

99. The if...elif...else executes only one block of code among several blocks. Choose one
a) True b) False c) It depends on expression used d) There is no elif
100. What is the output of the following code? >>> while 4 == 4:
print('4')
a) 4 b) 4 4 4 4 c) 4 is infinitely until program closes d) Syntax error

You might also like