Skip to content

Instantly share code, notes, and snippets.

@zikyfranky
Created July 8, 2018 22:34
Show Gist options
  • Save zikyfranky/fba3f25f24c29fa653a9c7b2799b42dc to your computer and use it in GitHub Desktop.
Save zikyfranky/fba3f25f24c29fa653a9c7b2799b42dc to your computer and use it in GitHub Desktop.
import random
print('''
This Code was created by Isaac Frank..
You can contact him on::
===============================================
Facebook: http://facebook.com/zikyfranky
===============================================
Twitter: http//twitter.com/zikyfranky
===============================================
Instagram: http://instagram.com/zikyfranky1
===============================================
Medium: http://medium.com/@isaacfrank
===============================================
WhatsApp: +2348118554697
===============================================
Website: Http://inforistic.com
''')
print('''
WELCOME
TO
ISAAC
SIMPLE PYTHON
GUESSING GAME''')
unknown = random.randint(1, 10)
tries = 0
win = False # setting a win flag to false
name = input("Hello, What is your username?")
print("Hello", name + ".", )
question = input("Would you like to play a game? [Y/N] ")
if question.lower() == "n": #in case of capital letters is entered
print("oh..okay")
exit()
if question.lower() == "y":
print("I'm thinking of a number between 1 & 10")
while not win: # while the win is not true, run the while loop. We set win to false at the start therefore this will always run
guess = int(input("Have a guess: "))
tries = tries + 1
if guess == unknown:
win = True # set win to true when the user guesses correctly.
elif guess < unknown:
print("Guess Higher")
elif guess > unknown:
print("Guess Lower")
while win:
# if win is true then output message
if tries == 1:
print("Congrats, you guessed correctly. The number was indeed {}".format(unknown))
print("it had taken you {} try".format(tries))
break
elif tries == random.randint(1,20):
print("Congrats, you guessed correctly. The number was indeed {}".format(unknown))
print("it had taken you {} tries".format(tries))
break
else:
print("Congrats, you guessed correctly. The number was indeed {}".format(unknown))
print("it had taken you above 20 tries")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment