Last active
December 20, 2021 09:25
-
-
Save Jithender5913/10a3f1e6c47f444a50e821b63d3ddb2e to your computer and use it in GitHub Desktop.
Number Guessing game using python
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
| logo = "welcome to number guessing game" | |
| print(logo) | |
| import random | |
| computer_choice = random.randint(1, 101) | |
| # print(f"psst! computer's number is {computer_choice}") to test code | |
| # Include an ASCII art logo. | |
| # Include two different difficulty levels (e.g., 10 guesses in easy mode, only 5 guesses in hard mode). | |
| # If they run out of turns, provide feedback to the player. | |
| # Allow the player to submit a guess for a number between 1 and 100. | |
| end_of_lives = True | |
| difficult_level = input("choose a difficulty level: easy or hard ") | |
| if difficult_level == "easy": | |
| lives = 10 | |
| else: | |
| lives = 5 | |
| while end_of_lives: | |
| user_guess = int(input("make a number guess between 1 and 100: ")) | |
| if user_guess != computer_choice: | |
| lives -= 1 | |
| print(f"remaining turns {lives}") | |
| if lives == 0: | |
| end_of_lives = False | |
| print("out of turns. you lose") | |
| # Check user's guess against actual answer. Print "Too high." or "Too low." depending on the user's answer. | |
| if user_guess > computer_choice: | |
| print("too high") | |
| elif user_guess < computer_choice: | |
| print("too low") | |
| # If they got the answer correct, show the actual answer to the player. | |
| # Track the number of turns remaining. | |
| if user_guess == computer_choice: | |
| end_of_lives = False | |
| print(f"you got it. That's the correct answer {computer_choice}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment