我正在尝试为我的飙车模拟游戏创建一个升级商店,但它一直显示“TypeError:输入预计最多 1 个参数,得到 19” 我对Python有点陌生,所以有人可以像新手一样帮我解释一下吗?
upgradeQ=input("\nWould you like to purchase an upgrade? (y/n) ")
while upgradeQ=="y":
upgradeList=int(input("\n1. Engine ($1000)",userEngine,"/ 5",
"\n2. Spoiler ($250)",userSpoiler,"/ 6",
"\n3. Body ($750)",userBody,"/ 6",
"\n4. Wheels ($500)",userWheels,"/ 10",
"\n5. Exhaust ($250)",userExhaust,"/ 5",
"\n6. Transmission ($500)",userTrans,"/ 4",
"Which upgrade would you like to purchase? (1-6) "))
# Engine Upgrades
if upgradeList==1 and (bank-enginePrice)<0:
print("\nYou do not have sufficient funds!")
upgradeQ=input("\nWould you like to purchase an upgrade? (y/n) ")
elif upgradeList==1 and (userEngine>=6):
print("\nYou have the maximum upgrades for engine.")
upgradeQ=input("\nWould you like to purchase an upgrade? (y/n) ")
elif upgradeList==1 and (bank-enginePrice)>0:
bank-=enginePrice
userEngine+=1
print("\nSuccess! You have purchased the Engine upgrade.")
upgradeQ=input("\nWould you like to purchase an upgrade? (y/n) ")
“您想购买哪个升级?(1-6)”))的upgradeList最后一行显示了TypeError
你的问题很可能就在这里
upgradeList=int(input("\n1. Engine ($1000)",userEngine,"/ 5",
"\n2. Spoiler ($250)",userSpoiler,"/ 6",
"\n3. Body ($750)",userBody,"/ 6",
"\n4. Wheels ($500)",userWheels,"/ 10",
"\n5. Exhaust ($250)",userExhaust,"/ 5",
"\n6. Transmission ($500)",userTrans,"/ 4",
"Which upgrade would you like to purchase? (1-6) "))
, 运算符不连接字符串。相反,每个逗号标记另一个参数。
functioncall(arg1, arg2, arg3) etc
输入函数只接受一个参数,从类型错误中可以看出。
将那些 , 更改为 + 就可以了。您可能需要将一些内容转换为字符串,但这是另一个问题(并且很容易通过谷歌搜索)
我猜您查看了 print 函数并假设这就是所有函数的工作原理。 Print 是一个例外,因为它是可变参数,因此可以接受任意数量的参数