File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ # Age Calculator – Beginner Python Project
2+
3+ This is a simple Python project for beginners to calculate a person's age based on the birth year.
4+
5+ ## File Structure
6+
7+ - ` age_calculator.py ` – Contains the logic to calculate age from the user's input.
8+
9+ ## ✅ How It Works
10+
11+ 1 . The user is asked to enter their ** birth year** .
12+ 2 . The program calculates the current year using Python's ` datetime ` module.
13+ 3 . It subtracts the birth year from the current year to get the ** age** .
14+ 4 . The age is then printed on the screen.
15+
16+ ## Skills You'll Learn
17+
18+ - Taking input from users
19+ - Working with Python's ` datetime ` module
20+ - Defining and calling functions
21+ - Basic math and string formatting
22+
23+ ## Run the Code
24+
25+ Open terminal and run:
26+
27+ ``` bash
28+ python age_calculator.py
29+
30+ Then enter your birth year (e.g., 2000) and get your age.
31+ Happy Coding! 🎉
Original file line number Diff line number Diff line change 1+ from datetime import date
2+
3+ def calculate_age (birth_year ):
4+ current_year = date .today ().year
5+ age = current_year - birth_year
6+ return age
7+
8+ # Ask user for their birth year
9+ birth_year = int (input ("Enter your birth year: " ))
10+ age = calculate_age (birth_year )
11+
12+ print (f"You are { age } years old." )
You can’t perform that action at this time.
0 commit comments