dimanche 29 mai 2022

Only loops through twice

I am making a random number game where there are two base numbers and you must guess what the number is between them. The problem is in my for loop it is only looping through once or twice. Where am I going wrong here?

Here is my code:

import random
opening_message = "Welcome to Higher/Lower game Bella!"
print(opening_message)

higher_number = int(input("Give us a higher number! "))

lower_number = int(input('Give us a lower number! '))

if lower_number > higher_number:
    print("Lower number must be less than higher number")
    lower_number = int(input('Give us a lower number! '))
else:
    guessed_number = int(input("Great, now Guess the number between {} and {}! ".format(lower_number, higher_number)))
    print(guessed_number)



num = random.randint(lower_number, higher_number)
for number in str(num):
    if guessed_number < num:
        print('Nope, too low try again!')
        guessed_number = int(input("Guess a new number!".format(lower_number, higher_number)))
    elif guessed_number > num:
        print('Nope, too high!')
        guessed_number = int(input("Guess a new number!! "))
    else:
        if guessed_number == num:
            print('correct! The number was {}'.format(num))
    print(' You did it!')
print('Great job Bella!')



Aucun commentaire:

Enregistrer un commentaire