-
Couldn't load subscription status.
- Fork 31
Add Age Calculator Python Project #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Shailaja-poojari
wants to merge
3
commits into
Grow-with-Open-Source:main
from
Shailaja-poojari:add-contrib-shailaja
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Age Calculator – Beginner Python Project | ||
|
|
||
| This is a simple Python project for beginners to calculate a person's age based on the birth year. | ||
|
|
||
| ## File Structure | ||
|
|
||
| - `age_calculator.py` – Contains the logic to calculate age from the user's input. | ||
|
|
||
| ## ✅ How It Works | ||
|
|
||
| 1. The user is asked to enter their **birth year**. | ||
| 2. The program calculates the current year using Python's `datetime` module. | ||
| 3. It subtracts the birth year from the current year to get the **age**. | ||
| 4. The age is then printed on the screen. | ||
|
|
||
| ## Skills You'll Learn | ||
|
|
||
| - Taking input from users | ||
| - Working with Python's `datetime` module | ||
| - Defining and calling functions | ||
| - Basic math and string formatting | ||
|
|
||
| ## Run the Code | ||
|
|
||
| Open terminal and run: | ||
|
|
||
| ```bash | ||
| python age_calculator.py | ||
|
|
||
| Then enter your birth year (e.g., 2000) and get your age. | ||
| Happy Coding! 🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| from datetime import date | ||
|
|
||
| def calculate_age(birth_year): | ||
| current_year = date.today().year | ||
| age = current_year - birth_year | ||
| return age | ||
|
|
||
| # Ask user for their birth year | ||
| birth_year = int(input("Enter your birth year: ")) | ||
| age = calculate_age(birth_year) | ||
|
|
||
| print(f"You are {age} years old.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Hello World in Python | ||
|
|
||
| This is a simple beginner-friendly Python project that prints a personalized "Hello, World" message. | ||
|
|
||
| ## File: `hello.py` | ||
|
|
||
| This script asks for the user's name and prints a greeting. | ||
|
|
||
| ### How it works: | ||
| - Takes input from the user | ||
| - Uses a function `say_hello(name)` to return a greeting message | ||
| - Prints the final message | ||
|
|
||
| ### To run: | ||
| ```bash | ||
| python hello.py | ||
|
|
||
| Example Output: | ||
| Enter your name: Shailaja | ||
| Hello, Shailaja! Welcome to the world of open source. | ||
|
|
||
|
|
||
| 🌟 Who is this for? | ||
| Perfect for first-time contributors to practice creating a Python script and contributing to open-source. | ||
|
|
||
|
|
||
| Contribution Steps: | ||
|
|
||
| Fork the repo | ||
| Clone to your system | ||
| Create a branch | ||
| Add your project | ||
| Commit and push | ||
| Create a Pull Request (PR) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,7 @@ | ||||||||||||||||
| def say_hello(name): | ||||||||||||||||
| return f"Hello, {name}! Welcome to the world of open source." | ||||||||||||||||
|
|
||||||||||||||||
| # Example usage | ||||||||||||||||
| if __name__ == "__main__": | ||||||||||||||||
| user_name = input("Enter your name: ") | ||||||||||||||||
| print(say_hello(user_name)) | ||||||||||||||||
|
Comment on lines
+1
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove any files that are not relevant to the PR.
Suggested change
|
||||||||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove any files that are not relevant to the PR.