Created
November 25, 2021 01:54
-
-
Save Elijah-trillionz/48a3334e370f4791e30ce36ef0441ea1 to your computer and use it in GitHub Desktop.
guess number game (users)
This file contains 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
# guess the number game. | |
import random as rd | |
def guess_number(): | |
computer_input = rd.randint(1, 10) | |
attempts = 2 | |
while attempts >= 0: | |
is_wrong = compare_guess(computer_input, attempts) | |
if is_wrong: | |
print(is_wrong) | |
else: | |
print('Guessed right') | |
break | |
attempts -= 1 | |
else: | |
print(f'Game over bro. The correct answer was {computer_input}') | |
def compare_guess(computer_input, attempts): | |
user_input = int(input('Guess a number between 1 and 10: ')) | |
if computer_input == user_input: | |
return False | |
elif computer_input > user_input: | |
return f'Too low. You have {attempts} more trials' | |
else: | |
return f'Too high. You have {attempts} more trials' | |
guess_number() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment