Python 错误输入最多应为1个参数,得到3个
每当我为我的输入输入一个3位数的数字时,我就会得到一个错误,即输入最多需要1个参数,得到3个。是否有办法解决此问题?由于输入调用中的逗号而导致此错误。 Python将它们解释为3个不同参数的分隔符 您仍然可以在输入调用中使用变量,最好的方法是 使用格式化字符串。 只需将lconfirm更改为:Python 错误输入最多应为1个参数,得到3个,python,input,error-handling,turtle-graphics,Python,Input,Error Handling,Turtle Graphics,每当我为我的输入输入一个3位数的数字时,我就会得到一个错误,即输入最多需要1个参数,得到3个。是否有办法解决此问题?由于输入调用中的逗号而导致此错误。 Python将它们解释为3个不同参数的分隔符 您仍然可以在输入调用中使用变量,最好的方法是 使用格式化字符串。 只需将lconfirm更改为: lmoney = (input("Sounds great! How much money would you like to bet on leonardo?($1-$10,000)(Plea
lmoney = (input("Sounds great! How much money would you like to bet on leonardo?($1-$10,000)(Please don't enter $ sign)")
lconfirm = input('Are you sure you want to put $',lmoney, 'on Leonardo?')
尝试使用
format
函数格式化字符串。input
函数实际上只接受一个参数,并且您提供了多个参数
lconfirm = input(f'Are you sure you want to put $ {lmoney} on Leonardo?')
根据的文档,只允许有一个参数。您的第一行有语法错误。你的括号不平衡。
lconfirm = input('Are you sure you want to put {} on Leonardo?'.format(lmoney))