❓ 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
  • 356
    Views
  • 1
    Participants
Last reply from:
Unknown user

Trending Topics

Online now

Members online
1,044
Guests online
4,639
Total visitors
5,683

Forum statistics

Threads
2,314,407
Posts
29,178,258
Members
1,184,125
Latest member
jewu1
Back
Top