Skip to content

Commit 8f54509

Browse files
Added Age Calculator project with Python code and README
1 parent 5137e1b commit 8f54509

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Age-Calculator/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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! 🎉

Age-Calculator/age_calculator.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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.")

0 commit comments

Comments
 (0)