mardi 13 décembre 2016

How can I make a loop with changing random numbers?

I want to make a game that will generate multipication equations. I want to make it that you will get a simple multipication equation (ex: 5*6) and when you answer it, the program will tell you if you are correct, and then will go to the next random equation. I know how to make it with a lot of different random numbers, but this will make the code very long and not ellegant. I need a way to generate two different random numbers every time, without having to make a data base of let's say 20 different random numbers. Does anyone know how to do it? Thanks!

this is the code iv'e wrote so far: import random import sys import os

random_num1 = random.randrange(1, 10)
random_num2 = random.randrange(1, 10)

print(random_num1, 'X', random_num2, '=', )

def multiplication(random_num1, random_num2):
sumNum = random_num1 * random_num2
return sumNum

one = input()

if(int(one) == multiplication(random_num1, random_num2)):
print('true')
else:
print('false')




Aucun commentaire:

Enregistrer un commentaire