Skip to content

Instantly share code, notes, and snippets.

@Elijah-trillionz
Created November 25, 2021 01:54
Show Gist options
  • Save Elijah-trillionz/48a3334e370f4791e30ce36ef0441ea1 to your computer and use it in GitHub Desktop.
Save Elijah-trillionz/48a3334e370f4791e30ce36ef0441ea1 to your computer and use it in GitHub Desktop.
guess number game (users)
# 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