0% found this document useful (0 votes)
27 views5 pages

Conditional - Statements - Practice - Questions G

python

Uploaded by

rohansalunke643
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)
27 views5 pages

Conditional - Statements - Practice - Questions G

python

Uploaded by

rohansalunke643
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/ 5

Conditional Statements Practice Questions and Answers

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:

age = int(input('Enter your age: '))

if age >= 18:

print('Eligible to vote')

else:

print('Not eligible to vote')

2. Create a program that asks the user for a number and prints whether the number is even

or odd.

Answer:

number = int(input('Enter a number: '))

if number % 2 == 0:

print('The number is even')

else:

print('The number is odd')

3. Write a program that takes the temperature in Celsius as input and prints 'It's hot outside!'

if the temperature is above 30, otherwise print 'The weather is cool.'.

Answer:

temperature = float(input('Enter the temperature in Celsius: '))

if temperature > 30:

print('It\'s hot outside!')

else:

print('The weather is cool.')


4. Write a program that asks the user for their exam score and prints the following grades

based on the score:

- Score >= 90: Grade A

- Score >= 75 and < 90: Grade B

- Score >= 50 and < 75: Grade C

- Score < 50: Grade F

Answer:

score = int(input('Enter your exam score: '))

if score >= 90:

print('Grade A')

elif score >= 75:

print('Grade B')

elif score >= 50:

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.

Otherwise, print 'Insufficient balance.'.

Answer:

balance = float(input('Enter your account balance: '))

withdraw = float(input('Enter the amount to withdraw: '))

if withdraw <= balance:

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:

- 'Stop!' if the color is red.

- 'Get ready to move' if the color is yellow.

- 'Go!' if the color is green.

- 'Invalid color' for any other input.

Answer:

color = input('Enter the traffic light color: ').lower()

if color == 'red':

print('Stop!')

elif color == 'yellow':

print('Get ready to move')

elif color == 'green':

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:

number = float(input('Enter a number: '))

if number > 0:

print('The number is positive')

elif number < 0:

print('The number is negative')

else:

print('The number is zero')

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:

price = float(input('Enter the price of the item: '))

discount = float(input('Enter the discount percentage: '))

if discount > 50:

print('Discount too high!')

else:

discounted_price = price - (price * discount / 100)

print(f'The discounted price is: {discounted_price}')

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:

password = input('Enter your password: ')

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:

num1 = float(input('Enter the first number: '))

num2 = float(input('Enter the second number: '))

num3 = float(input('Enter the third number: '))

if num1 >= num2 and num1 >= num3:

print(f'The largest number is: {num1}')


elif num2 >= num1 and num2 >= num3:

print(f'The largest number is: {num2}')

else:

print(f'The largest number is: {num3}')

You might also like