Skip to content
Advertisement

Python psychic guessing game repeats 10 times

I want it so it will randomly generate a number between 1-10 and the user will input their guess. It will then output if it is right or wrong, after 10 rounds it will tell them how psychic they are. I have done most of it but I cannot get it to randomly generate 10 numbers instead it generates 1 number and you can just input that number and get it correct every time if you find that number

import random
score=0
random=(random.randint(1,10))

for index in range(10):
    guess=int(input("Choose a number between 1 and 10:"))
    if random==guess:
        score+=1
        print ("Correct, Next")
    else:
        print ("Incorrect, Next")
    
if score==10:
    print("Final score:Super mystic")
elif score>=7:
    print("Final score:Good")
elif score>=5:
    print ("Final score:You need more practice")
else:
    print ("Final score:Dont become a psychic")

Advertisement

Answer

You need to put the random=(random.randint(1,10)) inside the for loop for it to change with every loop:

for index in range(10):
    random=(random.randint(1,10))
    guess=int(input("Choose a number between 1 and 10:"))

Then the rest of the code

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement