下面是一个简短的医生计划,我正在做,这是一个开始,不幸的是,它不起作用。这是我收到的错误- TypeError:输入最多应有1个参数,但得到4个
least = 0
most = 100
while True:
try:
levelofpain = int(input("How much is it hurting on a scale of", (least), "to", (most)))
while llevelofpain < least or levelofpain > most:
print ("Please enter a number from", (least), "to", (most))
levelofpain = int(input("How much is it hurting on a scale of", (least), "to", (most)))
break
except ValueError:
print ("Please enter a number from", (least), "to", (most))
提前谢谢!在
p.s.使用Python3.3
错误消息是不言自明的:您正在向
input(...)
传递四个参数,而它只接受一个参数。在解决方法是将参数转换为单个字符串。在
对于格式化字符串,您可能需要使用Python的
.format()
函数。看看这个问题:String Formatting in Python 3在Python中格式化字符串有两种主要方法,一种是使用
str
类的.format
方法,另一种是使用%
符号的旧C风格方法:str.格式():
C样式格式(%):
^{pr2}$我强烈建议不要使用C风格的格式,而是使用现代函数版本。另一种我不推荐的方法是用您自己的定义替换输入函数:
相关问题 更多 >
编程相关推荐