I'm wondering how to plus, subtract and multiply a randomly generated number from other random number with a random operator.
This is the code I've got so far:
ops = ['+','-','*']
op = random.choice(ops)
variable1 = random.randrange(1,10)
variable2 = random.randrange(1,10)
if op == '+':
answer = sum(var1+var2)
elif op == '-':
answer = sum(var1-var2)
elif op == '*':
answer = sum(var1*var2)
I usually get an error message: answer = sum(var1-var2) TypeError: 'int' object is not iterable
Sorry if this is a simple answer, still fresh to the whole python coding! :)
Aucun commentaire:
Enregistrer un commentaire