pythonloopswhile-looparguments

While loop expecting 1 argument but needing more


Im trying to make an upgrade store for my drag racing sim, but it keeps saying "TypeError: input expected at most 1 arguments, got 19" Im kinda new to python, so can someone help explain to me like a newbie?

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) ")

It says the TypeError right in the last line of upgradeList in "Which upgrade would you like to purchase? (1-6) "))


Solution

  • Your problem is most likely here

    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) "))
    

    The , operator doesn't concatenate strings. Instead each comma marks another argument.

    functioncall(arg1, arg2, arg3) etc
    

    The input function only accepts one argument, as you can see from the type error.

    Change those , to + and you should be ok. You may need to cast some things to strings, but that's another question (and easy to google)

    I'm going to guess that you looked at the print function and assumed that was how all functions worked. Print is an exception as it's variadic and so accepts any number of arguments