1

入力された5つのテストスコアの平均を見つけて、各文字スコアに関連する文字の成績を表示するクラスのプログラムに取り組んでいます。文字点数は10点制(A=90~100、B=80~89など)

これは私がこれまでにまとめたものですが、構文で「avg」を認識していないようです。助言がありますか?

def main():
    while true:
        grade = int(input('Enter grade: '))
        total += grade
        avg = calc_average(total)
        abc_grade = determine_grade(grade)

        print('Average grade is: ' avg)
        print('Letter grades for entered grades are: ' abc_grade)

    def calc_average(total):
       return total / 5

    def determine_grade(grade):
        if grade >= 90 and <= 100:
            return 'A'
        elif grade >= 80 and <= 89:
            return 'B'
        elif grade >= 70 and <= 79:
            return 'C'
        elif grade >= 60 and <= 69:
            return 'D'
        else:
            return 'F'

main()
4

4 に答える 4

3

使用する:

    print('Average grade is: '+str(avg))
    print('Letter grades for entered grades are: '+abc_grade)

また

    print('Average grade is: %.2f'%(avg))
    print('Letter grades for entered grades are: %s'%(abc_grade))
于 2013-10-27T05:00:53.413 に答える
1
_list = []


def calc_average(total):
    return total / 5


def determine_grade(grade):
    if grade >= 90 and grade <= 100:
        return 'A'
    elif grade >= 80 and grade <= 89:
        return 'B'
    elif grade >= 70 and grade <= 79:
        return 'C'
    elif grade >= 60 and grade <= 69:
        return 'D'
    else:
        return 'F'


while True:
    grade = int(input('Enter grade: '))
    _list.append(grade)

    avg = calc_average(sum(_list))
    abc_grade = ' '.join([determine_grade(mark) for mark in _list])

    if len(_list) > 5:
        break

print('Average grade is: ', avg)
print('Letter grades for entered grades are: ', abc_grade)
于 2013-10-27T05:02:58.940 に答える