❓ Help If statement program

PHC-kT

Limited Access
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
  • 363
    Views
  • 1
    Participants
Last reply from:
Unknown user

Trending Topics

Online now

Members online
1,229
Guests online
5,144
Total visitors
6,373

Forum statistics

Threads
2,328,815
Posts
29,244,754
Members
1,158,085
Latest member
daddybigd
Back
Top