简体   繁体   中英

Issue with "if" statement in combination with input and random numbers

I started today playing a little bit with python, so I'm really new.

Thanks!

import random
import sys
import os

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

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

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

one = input()

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

I don't know if you'd still need a 5 year late answer haha. However, here it is:

I also removed the other two imports, which weren't being used in the code.

So, this is what I did, so it could compare two values of the same type:

if int(one) == int(sumNum):
    print('true')
else:
    print('false')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM