pythontypeerror

TypeError: input expected at most 1 arguments, got 5


When I am trying to input get a number into the system I get an error.

userInput= int(input("What is", RanNum1," - ", RanNum2," = ?"))

That is the code in question and the error entails this:

Traceback (most recent call last):
  File "H:/Project/MathProgram.py", line 144, in <module>
    userAnswer = Addition(RanNum1, RanNum2)
  File "H:/Project/MathProgram.py", line 33, in Addition
    userInput= int(input("What is", RanNum1," - ", RanNum2," = ?"))
TypeError: input expected at most 1 arguments, got 5

I have no idea why!


Solution

  • This is five arguments being passed to input:

    input("What is", RanNum1, " - ", RanNum2, " = ?")
    

    Use f-strings to provide a single string to input.

    inputstring = f"What is {RanNum1} - {RanNum2} = ?"
    userInput= int(input(inputstring))