python - 输入的错误最多为1个参数,为3

标签 python input error-handling turtle-graphics

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?')
每当我输入一个3位数的数字时,我都会得到一个错误,提示输入最多为1个参数,为3。是否有办法解决此问题?

最佳答案

由于输入 call 中的(逗号)而出现此错误。
Python将它们解释为的分隔符3个不同的参数
仍然可以在输入调用中使用变量,最好的方法是
使用格式的字符串。
只需将lconfirm更改为:

lconfirm = input(f'Are you sure you want to put $ {lmoney} on Leonardo?')

关于python - 输入的错误最多为1个参数,为3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64379084/

相关文章:

python - 将 ASCII 字符转换为 "<Uxxx>"unicode 符号的脚本

python - numpy:将行中的重复值设置为 0

javascript - 使用javascript自动计算输入值的总和

PHP 游戏无法识别位置

python - 将 bash 脚本拆分为单独的命令并一一运行它们

使用buffreader进行JAVA编程

asp.net-mvc - 如何在ASP.NET MVC中使用[HandleError]属性?

php - 在 php 中,你如何记录错误但不向用户显示它们

c# - 我在C# “The type or namespace name does not exist in namespace”中收到错误

python - 严重难以捉摸的循环(绞尽脑汁!)