Posts tagged "guess-my-number-python"

Guess my number python script

Modify the Guess My Number game so that the player has a
limited number of guesses. If the player fails to guess in time,
the program should display an appropriately chastising
message.

# guess my number game
# the computer generates a number between 1 and 100
# and tells the user if the number entered is smaller or higher
# than the number picked randomally by the computer

import random
print("I'm thinking of a number between 1 and 100\n")
print("Try to guess it in 5 attempts\n")

guess_total = 0
random_number = int(random.randint(1, 100))
my_number = int(input("Introduceti numarul: "))


while guess_total < = 5 : if guess_total >= 4:
        print("You've reached the max number of tries")
        break
           
    elif my_number == random_number:
        guess_total += 1
        guess_total = int(guess_total)
        print("Great. You've guessed it in", guess_total,"tries")
        break
        
    elif my_number < random_number: guess_total += 1 guess_total = int(guess_total) print("You're number is too low\n") my_number = int(input("Introduceti numarul: ")) elif my_number > random_number:
        guess_total += 1
        guess_total = int(guess_total)
        print("You're number is too high")
        my_number = int(input("Introduceti numarul: "))

# end of my wannabe program