1. Construct a logical expression to represent each of the following conditions:
(i) score is greater than or equal to 80 but less than 90
2. Write an if statement that assigns 20 to the variable y and assigns 40 to the variable z if the variable x is greater than 100.
3. Write an if statement that assigns 0 to the variable b and assigns 1 to the variable c if the variable a is less than 10.
4. Write an if-else statement that assigns 0 to the variable b if the variable a is less than 10. Otherwise, it should assign 99 to the variable b.
5. What will be the output of the following code:
x = 14
print('Fun with condition')
if x > 5:
print('I am greater than 5')
if x > 10:
print('I am greater than 10')
if x > 15:
print('I am greater than 15')
6. What will be the output of the following code:
x = 14
print('Fun with condition')
if x > 5:
print('I am greater than 5')
elif x > 10:
print('I am greater than 10')
elif x > 15:
print('I am greater than 15')
else:
print('Who am I?')
7. What will be the output of the following code:
x = 9
if x >= 10:
print('I am 10')
print('Or greater than 10')
print('Hello Pyhon!')
if x >= 5:
print('I am 5')
print('Or greater than 5')
8. What will be the output of the following code:
age = 18
if age > 10:
print('More than ten')
if age < 20:
print('Less than twenty')
print('All done')
9. What will never print regardless of the value of x?
if x < 2:
print('Below 2')
elif x < 20:
print('Below 20')
elif x < 10:
print('Below 10')
else:
print('Something else')
For Lab Programming Questions click here.