❓ Help If statement program

PHC-kT

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.
 

About this Thread

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

Online now

Members online
1,244
Guests online
5,569
Total visitors
6,813

Forum statistics

Threads
2,350,068
Posts
29,365,880
Members
1,089,488
Latest member
amarah366
Back
Top