Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Guess game
# Paste your game code from Task 2 here to work on your upgrades
import random
def difficulty():
difficulty = int(input("We will be playing game of limits. Tell me your upper limit "))
return difficulty
def intro(diff):
name = input("What is your name ? ")
print(f"Hello {name}. I am thinking of a number between 1 and {diff}.")
def num_tries():
num = input("Input the number of tries :")
print( f'You have {num} tries to guess it right!')
return int(num)
def guess_game():
limit = difficulty()
intro(limit)
number = random.randint(1,limit)
tries = num_tries()
count = 0
while count < tries:
print(f"++++You have {tries - count} tries left++++")
guess = int(input("What is your guess? "))
if guess == 999:
print(f"Argghh you cheated! {number}")
else:
if guess == number:
print(f"Nice work! You guessed it in {count + 1} tries")
count = tries
elif guess < number:
print("Too low, Try again!")
elif guess > number:
print("Too high, Try again!")
count += 1
if number != guess:
print(f"You were unsuccessful, the number is {number}")
###################################
play = True
while play == True:
guess_game()
play_again = input("Do you want to play again? Y/N ")
if play_again != "Y":
print("see you again!")
play = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.