0

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

Thanks in advance!

p.s. using python 3.3

2 Answers2

2

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)))
tripleee
  • 175,061
  • 34
  • 275
  • 318
  • You could catenate `"string " + str(least) + " more string"` etc but that's hardly an improvement. Why would you want to avoid using a function? Functions are your friends. – tripleee Apr 29 '14 at 10:52
  • 1
    `print (str("Please enter a number from", (least), "to", (most)))` –  Apr 29 '14 at 15:54
0

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: ")
Community
  • 1
  • 1
ilent2
  • 5,171
  • 3
  • 21
  • 30
  • @user3584575 The typical method is just to use the `.format()` member of string, but see my edit for two other alternatives. You can also use the method triplee mentioned in his comment. – ilent2 Apr 29 '14 at 12:12