これはこれまでの私のコードです。私は4つのテストのスコアを入力するようにユーザーに促すコードを得ることができます。 「テスト番号Nのスコアを入力してください」と尋ねるようにしました。配列を使用するようにコードを変更するにはどうすればよいですか?
私の問題は、ユーザーが入力するものから入力値を抽出できることにあります。私の最終目標は、最も低いテストグレードを落とし、残りのスコアで平均を計算できるようにすることです。使用される入力データは99,99,99、および77です。
私は、X番号が割り当てられた変数からminを取りますが、ユーザー入力から取得する場合は取得しません。
def main():
scores = getNumbers()
def getNumbers():
testCountIs = 0
testNum = 4
totalScore = 0
for test in range(1, testNum+1):
print('Enter the score for test number', int(testCountIs+1), end='')
testScores = int(input(': '))
testCountIs += 1
main()
Edit2:以下はこのプログラムで動作するコードです。
def main():
scores = getNumbers()
print("The average with the lowest score dropped is: ",float(sum(scores))/len(scores))
def getNumbers():
scores=[]
for testNum in range(4):
print('Enter the score for test number',int(testNum+1),end='')
scores.append(int(input(': ')))
scores=[score for score in scores if min(scores)!=score]
return scores
main()
の平均外を見つける必要がありますだけで
それを返すそして、それに追加し、リストを定義する必要がありますこれは良い出発点でなければなりません://www.tutorialspoint.com/python/python_lists.htm – NPE
私はあなたがリストを意味すると思う... pythonには配列がありますが、 '[]'はリストと呼ばれます –
ループがゼロから始まる方が理にかなっています。 'test_score [test]'を割り当てます。基本的にはループインデックスを複製するだけなので、カウントは必要ありません。 – tripleee