Error - input expected at most 1 argument, got 3

Dustin Burns picture Dustin Burns · Apr 2, 2012 · Viewed 42.2k times · Source

I've set up the following for loop to accept 5 test scores. I want the loop to prompt the user to enter 5 different scores. Now I could do this by writing the input "Please enter your next test score", but I'd rather have each inputted score prompt for its associated number.

So, for the first input, I'd like it to display "Please enter your score for test 1", and then for the second score, display "Please enter your score for test 2". When I try to run this loop, I get the following error:

Traceback (most recent call last):
  File "C:/Python32/Assignment 7.2", line 35, in <module>
    main()
  File "C:/Python32/Assignment 7.2", line 30, in main
    scores = input_scores()
  File "C:/Python32/Assignment 7.2", line 5, in input_scores
    score = int(input('Please enter your score for test', y,' : '))
TypeError: input expected at most 1 arguments, got 3

Here's the code

def input_scores():
    scores = []
    y = 1
    for num in range(5):
        score = int(input('Please enter your score for test', y, ': '))

        while score < 0 or score > 100:
            print('Error --- all test scores must be between 0 and 100 points')
            score = int(input('Please try again: '))
        scores.append(score)
        y += 1
        return scores

Answer

&#211;scar L&#243;pez picture Óscar López · Apr 2, 2012

A simple (and correct!) way to write what you want:

score = int(input('Please enter your score for test ' + str(y) + ': '))