Advertisement
JkSoftware

Day 12 - Guess the Number

Nov 20th, 2021
1,127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. import logo
  2. import random
  3.  
  4. print(logo.logo)
  5. RANDOM_NUMBER = random.randint(1, 100)
  6. print(RANDOM_NUMBER)
  7. USER_DIFF = int(input("Type '1' for easy, or '2' for hard. "))
  8. print(USER_DIFF)
  9.  
  10.  
  11.  
  12. def game(randnum, usrdif):
  13.     player_lives = 10
  14.     if usrdif == 2:
  15.         player_lives = 5  
  16.     is_playing = True
  17.     while is_playing == True:
  18.         user_guess = int(input("Guess a number between 1 - 100 "))
  19.         if user_guess == randnum:
  20.             print(f"Congrats, You correctly guessed {randnum} with {player_lives} lives left!")
  21.             is_playing = False
  22.         else:
  23.             player_lives -= 1
  24.             if player_lives == 0:
  25.                 print(f"Sorry, You ran out of lives, better luck next time! The number I was thinking of was {randnum}")
  26.                 is_playing = False
  27.             if user_guess > randnum:
  28.                 print(f"Sorry, {user_guess} was too high, try lower next time. {player_lives} lives remaining")
  29.             if user_guess < randnum:
  30.                 print(f"Sorry {user_guess} was too low, try higher next time. {player_lives} lives remaining")
  31.  
  32. game(RANDOM_NUMBER, USER_DIFF)
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement