/  Python-Conditional-Statements-Quiz

This Quiz contains totally 10 Questions each carry 1 point for you.

1.In a Python program, a control structure:
Directs the order of execution of the statements in the program
Defines program-specific data structures
Manages the input and output of control characters
Dictates what happens before the program starts and after it terminates

Correct!

Wrong!

2.What signifies the end of a statement block or suite in Python?
}
A comment
A line that is indented less than the previous line
End

Correct!

Wrong!

3.The following if/elif/elsestatement will raise a KeyError exception
d = {'a': 0, 'b': 1, 'c': 0}
if d['a'] > 0:
    print('ok')
elif d['b'] > 0:
   print('ok')
elif d['c'] > 0:
   print('ok')
elif d['d'] > 0:
    print('ok')
else:
    print('not ok')
False
True

Correct!

Wrong!

4.What will be the output of given Python code?

str1="hello"

c=0

for x in str1:

if(x!="l"):

c=c+1   else:

pass

print(c)
2
0
4
3

Correct!

Wrong!

5.Which of the following is a valid for loop in Python?
for(i=0; i < n; i++)
for i in range(0,5):
for i in range(0,5)
for i in range(5)

Correct!

Wrong!

6.What is value of this expression:
'a' + 'x' if '123'.isdigit() else 'y' + 'b'
'ax'
'ab'
'axb'
'axyb'

Correct!

Wrong!

7.What will be the output of the following code?
x = 12
for i in x:
    print(i)
12
1 2
Error
None of the above

Correct!

Wrong!

8.Which will give different result from the others from the following Python code?
for i in range(0,5): print(i)
for j in [0,1,2,3,4]: print(j)
for k in [0,1,2,3,4,5]: print(k)
for l in range(0,5,1): print(l)

Correct!

Wrong!

9.Which of the following is true about the code below?
x = 3
if (x > 2):
   x = x * 2;
if (x > 4):
    x = 0;print(x)
for any value of x, x will always equal 0 after this code executes
after this code execution, if x is greater than 2, the value in x will be doubled
after this code execution, if x is greater than 2, x will be equal 0

Correct!

Wrong!

10.Which one of the following is a valid Python if statement
if a>=2 :
if (a >= 2)
if (a => 22)
if a >= 22

Correct!

Wrong!

Share the quiz to show your results !

Subscribe to see your results

Ignore & go to results

Python-Conditional-Statements-Quiz

You got %%score%% of %%total%% right

%%description%%

%%description%%

Where to go ?

Quizzes

Loading...