Reputation: 31
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
Upvotes: 0
Views: 216
Reputation: 940
Your error is because the input function received more than 1 argument. It received:
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))
Upvotes: 0
Reputation: 1036
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)))
Upvotes: 0
Reputation: 15390
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)))
Upvotes: 1