❓ Help If statement program

PHC-kT

Forum Expert
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.
 

About this Thread

  • 1
    Replies
  • 353
    Views
  • 1
    Participants
Last reply from:
Unknown user

Online now

Members online
1,303
Guests online
2,828
Total visitors
4,131

Forum statistics

Threads
2,299,434
Posts
29,130,111
Members
1,201,006
Latest member
Riswa
Back
Top