虽然循环期望1参数但需要更多

时间:2017-05-11 09:08:48

标签: python loops while-loop arguments

我试图为我的飙车模拟器制作一个升级商店,但它一直在说" 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) ")

它表示在&#34中的upgradeList的最后一行中的TypeError权限;您想要购买哪种升级? (1-6)&#34;))

1 个答案:

答案 0 :(得分:1)

你的问题很可能就在这里

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是一个例外,因为它是可变参数,所以接受任意数量的参数