Python input()函数参数错误:如何修复该TypeError问题?
Python input函数报错修复方案
问题原因
Python内置的input()函数仅接受最多1个参数(用于显示提示文本),你在代码中传入了art4和字符串两个参数,触发了TypeError。
修复方法
- 若
art4是字符串变量,通过字符串拼接合并参数:
part3 = input(art4 + 'you safely crossed the icy river.you walked and reached a house with three doors:red/blue/yellow\n')
- 用f-string格式化(Python 3.6及以上版本适用),提升代码可读性:
part3 = input(f"{art4}you safely crossed the icy river.you walked and reached a house with three doors:red/blue/yellow\n")
- 若
art4是需要单独展示的内容,可先打印再调用input:
print(art4) part3 = input('you safely crossed the icy river.you walked and reached a house with three doors:red/blue/yellow\n')
内容的提问来源于stack exchange,提问作者yaya maya
相关产品推荐
相关产品推荐

