最后打印成绩列表以及P或F.

时间:2017-07-15 03:17:30

标签: python python-2.7

这是我到目前为止的代码。最终结果需要询问用户输入分数,然后循环继续,直到输入-99,然后打印出分数以及其下的“P”或“F”。谁能帮助我做到这一点?

scores = []

def print_scores(copy_scores):
    for score in copy_scores[:-1:]:
       print(copy_scores[-1])

def find_min_odd(scores_list):
   return min(scores_list)

def set_grades(scores_list):
   grades = []
for score in scores_list:
   if score >= 50:
      grades.append('P')
   elif score < 50:
        grades.append('F')

for grade in grades:
  print('{:>2}'.format(grade)) 
while True:
   user_input = raw_input ("Please enter your score value: ")
   for score_value in user_input.split():
     if score_value == -99:
        break

scores.append(int(score_value))
  print_scores(scores)
  set_grades(scores)

print('minimum score:', find_min_odd(scores))

1 个答案:

答案 0 :(得分:0)

问题在于你的while循环。如下所示更改while循环,我希望以下代码能够提供您想要的内容

def find_min_odd(scores_list):
    return min(scores_list)

grades = []
def set_grades(scores_list):
    for score in scores_list:
        if score >= 50:
            grades.append([score,'P'])
        elif score < 50:
            grades.append([score,'F'])
    return grades

user_input = 0 

scores_list = []

while int(user_input) != -99:
    user_input = input('Please enter your score value')
    if int(user_input) != -99:
        scores_list.append(int(user_input))

for grade in set_grades(scores_list):
    print("Score: " + str(grade[0]), "Result:" + grade[1])

print('minimum score:', find_min_odd(scores_list))

输出:

Please enter your score value 20
Please enter your score value 50
Please enter your score value 70
Please enter your score value -99
Score: 20 Result:F
Score: 50 Result:P
Score: 70 Result:P
minimum score: 20