From dfa987d1396b5dcd89fb48b5c82c0b05922ac6b6 Mon Sep 17 00:00:00 2001 From: pulkittillion Date: Fri, 31 Oct 2025 18:35:09 +0530 Subject: [PATCH] Add: CLI - AgeGuessr Name-to-Age Predictor --- Domains/cli/MiniProjects/AgeGuessr/README.md | 15 +++++++ .../cli/MiniProjects/AgeGuessr/age_guesser.py | 42 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 Domains/cli/MiniProjects/AgeGuessr/README.md create mode 100644 Domains/cli/MiniProjects/AgeGuessr/age_guesser.py diff --git a/Domains/cli/MiniProjects/AgeGuessr/README.md b/Domains/cli/MiniProjects/AgeGuessr/README.md new file mode 100644 index 00000000..7b755e67 --- /dev/null +++ b/Domains/cli/MiniProjects/AgeGuessr/README.md @@ -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 \ No newline at end of file diff --git a/Domains/cli/MiniProjects/AgeGuessr/age_guesser.py b/Domains/cli/MiniProjects/AgeGuessr/age_guesser.py new file mode 100644 index 00000000..8d87399f --- /dev/null +++ b/Domains/cli/MiniProjects/AgeGuessr/age_guesser.py @@ -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() \ No newline at end of file