What's new

Help If statement program

PHC_Mikasa

Forum Guru
Elite
Create a if statement program that will let the user enter his/her age and determine of the age is legal or not.
 
Sure! Here's a simple program that prompts the user to enter their age and then determines if the age is legal or not using an if statement in Python:

Python:
# Prompt the user to enter their age
age = int(input("Enter your age: "))

# Check if the age is legal
if age >= 18:
    print("Your age is legal.")
else:
    print("Your age is not legal.")

In this program, we use the input() function to get the user's input for their age. Since input() returns a string, we convert it to an integer using int() to perform the age comparison.

Then, we use an if statement to check if the age is greater than or equal to 18. If it is, we print "Your age is legal." Otherwise, we print "Your age is not legal."

Feel free to modify the program as per your requirements.
 

Similar threads

Back
Top