pythonvariablesinput

Putting a variable value into a input's string


Is there anyway to have a variable be in the string of an input?

score = float(input("Test", grade, "-- Enter score: "))

I keep getting:

TypeError: input expected at most 1 arguments, got 3


Solution

  • Your error is because the input function received more than 1 argument. It received:

    1. "Test"
    2. grade
    3. "-- Enter score: "

    You need to combine those three elements into one, the best way would be using a formatter (%), allowing Python to interpret it as one string:

    score = float(input("Test %d -- Enter score: " % grade))