lundi 18 novembre 2019

Why random is giving wrong output

I wrote one program for math game. find the total score. it will ask twice the user for the answer if its correct it will add 10. score is not adding

import random
def game():
    l = ['*','+']
    score = 0
    for _ in range(2):
        x = random.randint(1,5)
        y = random.randint(1,5)
        z = int(input("Enter the val of {} {} {} \n".format(x, random.choice(l), y)))
        if random.choice(l) == '*':
            o = x * y
        elif random.choice(l) == '+':
            o = x + y
        if z == o:
            score = score + 10
            print(score)
    return("Your score is {}".format(score))

game()



Aucun commentaire:

Enregistrer un commentaire