Quiz on Conditional Statements in Python
Q.1. What is the output of the following code?
print(1, end=" ")
if(False == False):
print(2, end=" ")
print(3,end=" ")
Q.2. Fill in the correct operators in the blank place.
x = 10
if x __ 0:
print("Value is greater than 0.")
elif x __ 0:
print("Value is less than 0.")
else:
print("Value is Zero.")
Q.3. In a Python program, a control structure:
Q.4. Which statement will check if a is equal to b?
Q.5. Which of the following represents the correct order for keywords?
Q.6. Given the nested if-else structure below, what will be the value of x after code execution
completes
x = 0
a = 0
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)
Q.7. What is the output of the following if statement -
a, b = 12, 5
if a + b:
print('True')
else:
print('False')
Q.8. What keyword would you use to add an alternative condition to an if statement?
Q.9. What signifies the end of a statement block or suite in Python?
Q.10. Consider the following code segment:
What letters will be printed if the user enters -1 for a and -1 for b?
a = int(input("Enter an integer: "))
b = int(input("Enter an integer: "))
if a <= 0:
b = b +1
else:
a = a + 1
if a > 0 and b > 0:
print ("W")
elif a > 0:
print("X")
if b > 0:
print("Y")
else:
print("Z")
Q.11. What is output for:
if 'bar' in {'foo': 1, 'bar': 2, 'baz': 3}:
print(1,end=" ")
print(2, end=" ")
if 'a' in 'qux':
print(3, end=" ")
print(4,end=" ")
Q.12. Which one of the following is a valid Python if statement :
Q.13. What is the possible output of the following code?
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')
Q.14. Can we write if/else into one line in python?
Q.15. What will be output of this expression:
print('p' + 'q' if '12'.isdigit() else 'r' + 's')
Instructions:-
- This Quiz is based on Conditional Statements in Python
- Each correct answer will carry 2 points
- Once an option is selected you cannot select any other, So choose wisely
- Do not refresh the page as it will reset the quiz
- Once the time is up the quiz will automatically get submitted with no of Question responded
- Your total score alongwith your name will be shown after submission of the Quiz
- Wish you ALL THE BEST 👍👍
START
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP