如何添加功能

时间:2017-07-13 18:45:03

标签: python python-2.7

我如何添加功能?由于我们正在学习本章的功能,因此我必须为此程序实现一个。这是我的代码到目前为止:     得分= []

def print_scores(copy_scores):
   for i in range(len(copy_scores)):
       print (copy_scores[i],)

scores = [75, 84, 66, 99, 51, 65]
print_scores (scores)
print ()

while True:
   scores = int(input("Please enter your score values"))
if scores == -99:
    break

Sample output:
75, 84, 66, 99, 51, 65
 P   P   P   P   F   P

1 个答案:

答案 0 :(得分:0)

scores = []
grades = []

def print_scores(copy_scores):
    print(', '.join(str(score) for score in copy_scores))

def find_min_odd(scores_list):
    if not scores_list:
        return []
    if scores_list[0] % 2 == 1:
        return [scores_list[0]] + find_min_odd(scores_list[1:])
    return find_min_odd(scores_list[1:])



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

print(''.join(str(grade) for grade in grades))

while True:
    user_input = input("Please enter your score value: ")
    if int(user_input) == -99:
        break
    scores.append(int(user_input))

print_scores(scores)
set_grades(scores)

print(', '.join(grade for grade in grades))
print('minimum odd score:', min(find_min_odd(scores)))

演示:

Please enter your score value: 75
Please enter your score value: 84
Please enter your score value: 66
Please enter your score value: 99
Please enter your score value: 51
Please enter your score value: 65
Please enter your score value: -99
75, 84, 66, 99, 51, 65
P, P, P, P, P, P
minimum odd score: 51