The most common answers for the 4.4.7 Teenagers CodeHS is:
# Enter your code here
age = int(input("What is your age? "))
if age >= 13 and age <= 19:
print("Yes, you are a teenager.")
else:
print("No, you are not a teenager.")
This code for determining whether someone is a teenager based on their age is functionally correct. However, it lacks proper indentation, which is essential in Python for defining the scope of conditional statements. Here’s your code with the correct indentation:
age = int(input("What is your age? "))
if 13 <= age <= 19:
print("Yes, you are a teenager.")
else:
print("No, you are not a teenager.")
In this code:
- The age is taken as input from the user and converted into an integer.
- The
if
statement checks if the age is between 13 and 19, inclusive. This is done using Python’s chained comparison, which is a more concise way to check if a value falls within a certain range. - Depending on the condition, it prints out whether the person is a teenager or not.
This script will work as expected, asking for the user’s age and then confirming if they are a teenager based on the age provided.
Leave a comment