samedi 24 octobre 2020

random choice is always return 1 as answer(simple game) [closed]

ok, I'm new to python(or coding in general) and I was trying to make a simple guessing game, the program decides on a number from 1 to 5 and the player tries to guess it, but every time I answer 1 it says correct, even when it is another number when you print. another problem I've been having is that the loop only lasts a short time, is that supposed to happen?

        import random
            num_list = [1, 2, 3, 4, 5,]
            num = random.choice(num_list)
            ur_num = input("pick a number, 1 to 5")

            for num in num_list:
                if int(ur_num) != num:
                    print("try again")
                    ur_num = input("pick a number, 1 to 5")
                else:
                    print("GOOD JOB")
                    again = input("wanna play again?(y/n)")
                    if again == "y":
                        num = random.choice(num_list)
                        print("OKIE DOKIE")
                    else:
                        print("Have a nice day!")
                        break



Aucun commentaire:

Enregistrer un commentaire