Skip to content

Instantly share code, notes, and snippets.

@hackorum
Last active March 22, 2021 15:17
Show Gist options
  • Save hackorum/de4f64bdf418f21353534025563e3118 to your computer and use it in GitHub Desktop.
Save hackorum/de4f64bdf418f21353534025563e3118 to your computer and use it in GitHub Desktop.
import random
randomNumber = random.randint(0, 9)
chancesLeft = 5
yellow = '\033[33m'
red = '\033[31m'
green = '\033[32m'
reset = '\033[m'
print(yellow, 'Oh, its locked! Help me enter the correct key! Hint: It is something between 0 and 9', reset)
while chancesLeft > -1:
guess = int(input('Your guess: '))
if guess > randomNumber:
print(red + 'Oh no! It was less than ' + str(guess), reset)
chancesLeft -= 1
elif guess < randomNumber:
print(red + 'Oh no! It was more than ' + str(guess), reset)
chancesLeft -= 1
else:
print(green + 'Success! You have opened it!', reset)
break
if chancesLeft == 0:
print('You were not able to enter it!')
playAgain = input('Do you want to try again? y/n ')
if playAgain == 'y':
chancesLeft = 5
randomNumber = random.randint(0, 9)
else:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment