Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Domains/cli/MiniProjects/AgeGuessr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# AgeGuessr: Name-to-Age Predictor

A fun and lightweight CLI tool that estimates the average age of a person based on their first name using real global data from [Agify.io](https://agify.io).

## Features
- Real-time age estimation from public dataset
- Clean, colorful terminal output
- No external dependencies (pure Python)
- Great for team icebreakers or curiosity!

## How to Run
1. Make sure you have Python 3 installed.
2. Navigate to the project folder:
```bash
cd Domains/CLI/MiniProjects/AgeGuessr
42 changes: 42 additions & 0 deletions Domains/cli/MiniProjects/AgeGuessr/age_guesser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import urllib.parse
import urllib.request
import json

def get_age_from_name(name):
"""Fetch estimated age for a given name using Agify.io API."""
safe_name = urllib.parse.quote(name)
url = f"https://api.agify.io/?name={safe_name}"

try:
with urllib.request.urlopen(url) as response:
data = json.loads(response.read().decode())
if data.get("age") is not None:
return data["name"], data["age"], data.get("count", 0)
else:
return name, None, 0
except Exception:
return name, None, 0

def main():
print("\033[1;95m🔮 AgeGuessr: How old is your name?\033[0m")
print("\033[90m(Uses global data to guess the average age for a given first name!)\033[0m\n")

name = input("Enter a first name: ").strip()

if not name:
print("❌ Name cannot be empty!")
return

guessed_name, age, count = get_age_from_name(name)

print("\n" + "="*50)
if age is not None:
print(f"📊 Name: \033[1m{guessed_name.title()}\033[0m")
print(f"👴 Estimated Average Age: \033[1;92m{age} years\033[0m")
print(f"🌍 Based on \033[1;96m{count:,}\033[0m records")
else:
print(f"❓ Sorry! No age data found for '\033[1m{name.title()}\033[0m'.")
print("="*50 + "\n")

if __name__ == "__main__":
main()
Loading