jeudi 29 septembre 2022

I am having wrong output in roll dice game when my guess matches the random dice output [duplicate]

I am building a game where the user has to guess which number between 1 and 6 the dice will role. Once the user gets the right guess they are supposed to receive a congratulatory message and if their guess is wrong they get try again

however even when guess matches the random output they get the message try again and not you win here is my code below please help me understand where i am going wrong

also i have changed the random to just 2 numbers instead of 6 to ensure user gets a quicker match once i figure out where problem is i will return random pool to 6

from random import randint
while True:
    dice = random.randint(1,2)
    user = input("choose a number between 1 and 6: ")
    print("The dice is: ", dice)
    print("You choose: ", user)
    
    if user == dice:
        print("you win")
    elif dice != user:
        print('try again')
    else:
        pass
    
    play_again = input('Would you like to play again, yes or no?')
    
    if play_again != 'yes':
        print("Goodbye")
        break



Aucun commentaire:

Enregistrer un commentaire