0
当我运行这个程序为什么随机整数的上限不是20? (Python 3中)
print('Welcome to the algebra machine!')
from random import *
a=randint(1,20)
b=(input('Choose a number:'))
c=a*b
print('You got a total of',c)
d=(input('What was the original number?'))
if d==a:
print('Correct!')
else:
print('Wrong!')
我会得到的最终答案,例如,如果22222222
我进入2
。 为什么不randint
上限为20
?
要添加到答案:你可以使用到Python 2.x的,其中'输入()'函数的输入转换为它的默认类型。然而,在Python 3.x中,输入仍然是一个字符串。如果你想要另一种类型,程序需要明确地进行转换。 –