Skip to content

Instantly share code, notes, and snippets.

@kevincolyer
Created November 28, 2021 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevincolyer/c32e1f0e416d101d1bc1e4f90a95345d to your computer and use it in GitHub Desktop.
Save kevincolyer/c32e1f0e416d101d1bc1e4f90a95345d to your computer and use it in GitHub Desktop.
Guess the Number game in Python
import random
num = random.randint(1, 100)
print(f'I\'m thinking of a number from 1 to 100. What number am I thinking of?')
for count in range(7,0,-1):
print(f"\nYou have {count} guesses.\nWhat is your guess?\n>", end = '');
i=0
getting_input = True
while getting_input:
i = int(input())
if i<1 or i>100:
print("Please enter a whole number from 1 to 100\n>", end = '')
else: getting_input = False
print(f"[{i}]: ",end='')
if i>num:
print("Too high!")
elif i < num:
print("Too low!")
elif i == num:
print(f"That's it! You guessed correctly!")
quit()
print(f"You lose! The number was {num}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment