Reputation: 1
Below is a short doctor program that I am making and this is the start, unfortunately, it doesn't work. Here is the error I receive - TypeError: input expected at most 1 arguments, got 4
least = 0
most = 100
while True:
try:
levelofpain = int(input("How much is it hurting on a scale of", (least), "to", (most)))
while llevelofpain < least or levelofpain > most:
print ("Please enter a number from", (least), "to", (most))
levelofpain = int(input("How much is it hurting on a scale of", (least), "to", (most)))
break
except ValueError:
print ("Please enter a number from", (least), "to", (most))
p.s. using python 3.3
Upvotes: -1
Views: 731
Reputation: 5241
For formatting strings, you probably want to use Python's .format()
function. Take a look at this question: String Formatting in Python 3
There are two main methods for formatting strings in Python, the new way using the .format
method of the str
class, and the old C style method of using the %
symbol:
str.format():
"This is a string with the numbers {} and {} and {0}".format(1, 2)
C Style Format (%):
"This is another string with %d %f %d" % (1, 1.5, 2)
I strongly recommend not using the C Style Format, instead use the modern function version. Another way I don't recommend is replacing the input function with your own definition:
old_input = input
def input(*args):
s = ''.join([str(a) for a in args])
return old_input(s)
input("This", "is", 1, 2, 3, "a test: ")
Upvotes: 0
Reputation: 189908
The error message is self-explanatory -- you are passing four arguments to input(...)
where it is only accepting one.
The fix is to turn the argument into a single string.
levelofpain = int(input(
"How much is it hurting on a scale of {} to {}? ".format(least, most)))
Upvotes: 2