5 つのテスト スコアを受け入れるために、次の for ループを設定しました。ユーザーに 5 つの異なるスコアを入力するように求めるループが必要です。「次のテストスコアを入力してください」という入力を書くことでこれを行うことができますが、入力されたスコアごとに関連する番号を求めるプロンプトが表示されるようにしたいと思います。
ですので、1回目の入力は「テスト1の点数を入力してください」、2回目の入力は「テスト2の点数を入力してください」と表示させたいです。このループを実行しようとすると、次のエラーが発生します。
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
これがコードです
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