Created
June 30, 2020 04:12
-
-
Save mambodin/2b0698998e616ab7dde381a9ec5cf33d to your computer and use it in GitHub Desktop.
Guess game
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
# 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