Solution: Movie Night
Understand how to write a Python program that asks for user input, converts it to a number, and uses conditional logic to decide if the user can watch a movie based on their age. This lesson helps you practice basic input handling, type conversion, and if-else statements.
We'll cover the following...
We'll cover the following...
This program checks a user’s age and decides whether they’re old enough to watch a movie.
input()asks the user to enter their age.int()converts the input (which is text) into a number so Python can compare it.The
ifstatement checks a condition:If the user’s age is 13 or older (
age >= 13), Python runs the firstprint()statement.Otherwise, it runs the
elsepart and prints the message for users under 13.
age = int(input("How old are you? "))
if age >= 13:
print("Enjoy the movie!")
else:
print("Sorry, you're too young.")Code that checks if the user is old enough to watch a movie