python报错TypeError
setting = input('输入你想猜数的范围(N,n):')answer = int(random.randint(setting))
Traceback (most recent call last):
File "E:\OneDrive - qianbiao\AAAAApy\旧\P5.py", line 4, in <module>
answer = int(random.randint(setting))
TypeError: randint() missing 1 required positional argument: 'b'
函数功能:
random.randint(参数1,参数2)
参数1、参数2必须是整数
函数返回参数1和参数2之间的任意整数(input接收的是字符串,要转换为整数)
举例:
import random
result = random.randint(1,10)
print("result: ",result)
输出:
result: 6 {:10_266:} 本帖最后由 昨非 于 2020-10-2 11:32 编辑
setting = int(input('输入你想猜数的范围(N,n):'))
answer = random.randint(0,setting)
print(answer)
参数需要整型,input的返回值为字符串
谢了各位!
页:
[1]