Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #GUESS THE NUMBER
- import random
- import sys
- attempts_list = []
- def show_score():
- if len(attempts_list) <= 0:
- print("No score yet! Play the game to get a score!")
- else :
- print(f"Last score achieved with {attempts_list} attempts!")
- print(f"Beat your highscore of {min(attempts_list)} attempts!")
- def start_game():
- random_num = int(random.randint(1,10))
- print("-------------------------")
- print("Guess the Number Game!")
- print("-------------------------")
- name = input("Please enter your name: ")
- ready = input("Are you ready " + name + " ? ")
- attempts = 0
- show_score()
- while ready == "Yes" or ready == "yes":
- try:
- print()
- guess = int(input("Guess a number 1-10! "))
- if int(guess) < 0 or int(guess) > 10:
- raise ValueError
- if int(guess) == random_num:
- print(f"GREAT {name}! You've guessed it!")
- attempts += 1
- attempts_list.append(attempts)
- print(f"With a total of {attempts} attempts!")
- play_again = input("Wanna play again? ")
- attempts = 0
- show_score()
- random_num = int(random.randint(1, 10))
- if play_again == "no" or play_again == "No":
- print("Cool! Do try again next time!")
- sys.exit()
- elif int(guess) < random_num:
- print("Go Higher!")
- attempts += 1
- elif int(guess) > random_num:
- print("Go Lower!")
- attempts += 1
- except ValueError:
- print("Not a valid answer..!")
- print("Please enter a number from 1-10 & NOT a letter.")
- else:
- print()
- print("Okeyy bye!")
- start_game()
- #Talice ~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement