Conditional - Statements - Practice - Questions G
Conditional - Statements - Practice - Questions G
1. Write a program that asks the user for their age and checks if they are eligible to vote.
Print 'Eligible to vote' if the age is 18 or more, otherwise print 'Not eligible to vote'.
Answer:
print('Eligible to vote')
else:
2. Create a program that asks the user for a number and prints whether the number is even
or odd.
Answer:
if number % 2 == 0:
else:
3. Write a program that takes the temperature in Celsius as input and prints 'It's hot outside!'
Answer:
else:
Answer:
print('Grade A')
print('Grade B')
print('Grade C')
else:
print('Grade F')
5. Write a program that asks the user for their account balance and the amount they want to
withdraw. Print 'Withdrawal successful' if the amount is less than or equal to the balance.
Answer:
print('Withdrawal successful')
else:
print('Insufficient balance')
6. Create a program that asks the user for the traffic light color (red, yellow, or green) and
prints:
Answer:
if color == 'red':
print('Stop!')
print('Go!')
else:
print('Invalid color')
7. Write a program that takes a number as input and checks if it is positive, negative, or zero.
Answer:
if number > 0:
else:
8. Write a program that asks the user for the price of an item and the discount percentage. If
the discount is greater than 50%, print 'Discount too high!' Otherwise, calculate and print the
discounted price.
Answer:
else:
9. Write a program that takes a user's password as input and checks if it matches a
predefined password. Print 'Access granted' if it matches, otherwise print 'Access denied.'.
Answer:
predefined_password = 'mypassword'
if password == predefined_password:
print('Access granted')
else:
print('Access denied')
10. Create a program that takes three numbers as input and prints the largest among them.
Answer:
else: