0

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

1
  • You have to concatenate using + or format with input. Input is not like print Commented Oct 7, 2016 at 6:14

3 Answers 3

1

You are passing 3 strings, should be only one. You're incorrectly concatenating string. Use format for that

score = float(input("Test {} -- Enter score: ".format(grade)))
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

You can use % or format to put variable into string:

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

or

score = float(input("Test {} -- Enter score: ".format(grade)))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.