script_1.py - Simple Age Checker
Code
Python
#!/usr/bin/env python3
"""Simple age checker"""
age = int(input("Enter your age: "))
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.")
Explanation
Line 4: age = int(input("Enter your age: "))
- input() returns a string type (str) containing user input
- int() converts that string to an integer type (int)
- age stores the integer value
- If user enters non-numeric text, int() will raise a ValueError
Line 6: if age >= 18:
- >= is the greater-than-or-equal comparison operator
- Returns a boolean (True or False)
- Checks if age is 18 or higher
Line 7: print("You are an adult.")
- print() outputs text to stdout (terminal)
- Only executes if the condition on line 6 is True
Line 8: else:
- Executes when the if condition is False (age < 18)
- Handles all cases not caught by the if block