Guess the number

mail@pastecode.io avatar
unknown
python
21 days ago
764 B
7
Indexable
Never
import random

def generate_random_number():
    random_number = random.randint(1, 100)
    return random_number

def guess_number_game():
    counter =  0
    while True:
       number_guess = int(input("Guess the number:"))
       counter +=1
       match number_guess:
          case num if number_guess > random_number:
            print('The number is too high!')
          case num if number_guess < random_number:
            print('The number is too low!')
          case num if number_guess == random_number:
            print('Congratulations!')
            break
       if counter == 10:
          print ('Game Over')
          break

if __name__ == "__main__":
   random_number = generate_random_number()
   guess_number_game()
Leave a Comment