Created
November 28, 2021 19:04
-
-
Save kevincolyer/c32e1f0e416d101d1bc1e4f90a95345d to your computer and use it in GitHub Desktop.
Guess the Number game in Python
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
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