-
Notifications
You must be signed in to change notification settings - Fork 36
Enhance Animal Guess Game with improved logic, random questions, and replay option #42
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
Open
swati-londhe
wants to merge
2
commits into
Grow-with-Open-Source:main
Choose a base branch
from
swati-londhe:feature-enhance-animal-guess-game
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+59
−22
Open
Changes from all commits
Commits
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 |
|---|---|---|
| @@ -1,25 +1,49 @@ | ||
| import random | ||
|
|
||
| def check_guess(guess, answer): | ||
| global score | ||
| still_guessing = True | ||
| """Check user's guess and return True if correct.""" | ||
| attempt = 0 | ||
| while still_guessing and attempt < 3: | ||
| while attempt < 3: | ||
| if guess.lower() == answer.lower(): | ||
| print("Correct Answer") | ||
| score = score + 1 | ||
| still_guessing = False | ||
| print("✅ Correct Answer!\n") | ||
| return True | ||
| else: | ||
| if attempt < 2: | ||
| guess = input("Sorry Wrong Answer, try again") | ||
| attempt = attempt + 1 | ||
| if attempt == 3: | ||
| print("The Correct answer is ",answer ) | ||
|
|
||
| score = 0 | ||
| print("Guess the Animal") | ||
| guess1 = input("Which bear lives at the North Pole? ") | ||
| check_guess(guess1, "polar bear") | ||
| guess2 = input("Which is the fastest land animal? ") | ||
| check_guess(guess2, "Cheetah") | ||
| guess3 = input("Which is the larget animal? ") | ||
| check_guess(guess3, "Blue Whale") | ||
| print("Your Score is "+ str(score)) | ||
| attempt += 1 | ||
| if attempt < 3: | ||
| guess = input("❌ Wrong! Try again: ") | ||
| print(f"The correct answer is: {answer}\n") | ||
| return False | ||
|
|
||
|
|
||
| def main(): | ||
| print("🐾 Welcome to the Animal Guessing Game! 🐾") | ||
| print("You have 3 attempts for each question.\n") | ||
|
|
||
| questions = { | ||
| "Which bear lives at the North Pole?": "polar bear", | ||
| "Which is the fastest land animal?": "cheetah", | ||
| "Which is the largest animal?": "blue whale", | ||
| "Which animal is known as the king of the jungle?": "lion", | ||
| "Which animal can sleep standing up?": "horse" | ||
| } | ||
|
|
||
| score = 0 | ||
| # Randomize question order | ||
| for question, answer in random.sample(list(questions.items()), 3): | ||
| guess = input(question + " ") | ||
| if check_guess(guess, answer): | ||
| score += 1 | ||
|
|
||
| print(f"🎯 Your final score is: {score}/{len(questions)}") | ||
|
|
||
| # Option to play again | ||
| replay = input("\nDo you want to play again? (yes/no): ") | ||
| if replay.lower().startswith('y'): | ||
| print("\nRestarting game...\n") | ||
| main() | ||
| else: | ||
| print("Thanks for playing! 🦋") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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
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 the changes made to this file. Each PR should be isolated to one single purpose, and the changes made to this file don't belong here.
You can perform interactive rebasing to remove the commit that contains the changes to this file. And if you use rebasing, your commit history will change, so force-push your changes to this branch.
Important
If you're stuck or unable to do it, please ping @iamwatchdogs in the conversation tab of this PR.