python input character limit 1

python input character limit

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

Here is what the above code is Doing:
1. It creates an empty list called scores.
2. It creates a variable called y and assigns it the value 1.
3. It creates a for loop that will run 5 times.
4. It asks the user to enter a score.
5. It checks to make sure the score is between 0 and 100.
6. If the score is not between 0 and 100, it asks the user to try again.
7. If the score is between 0 and 100, it adds the score to the list called scores.
8. It adds 1 to the variable y.
9. It returns the list called scores.

Similar Posts