0

どうすればいいのか、なんとなくわかったのですが、なかなか思いつきません。プログラムは、生徒の名前と 3 つのテストの点数を取得し、3 つの点数の平均点 (パーセンテージ) を取得できる必要があります。その後、スコア(パーセンテージ)をグレードに変換する必要があります。

編集: グレードの途中のスペースと「%」を削除するにはどうすればよいですか?

  • 開始するには「Enter」を押してください
  • 名前を入力してください: Jordan Simpson
  • 最初のテストの点数: 67%
  • 2回目のテストスコア: 78%
  • 3回目のテストスコア: 89%
  • 最終文字グレード: C+
  • ジョーダン・シンプソンのテストスコア: 78.0 %
  • プログラムを再起動しますか?

評価尺度:

評価尺度


input ('Please press "Enter" to begin')

while True:
    import math

    studentName = str(input('Enter your Name: '))
    firstScore = int(float(input('First test score: ').replace('%', '')))
    secondScore = int(float(input('Second test score: ').replace('%', '')))
    thirdScore = int(float(input('Third test score: ').replace('%', '')))
    scoreAvg = (firstScore + secondScore + thirdScore) / 3

    def grade():
        if scoreAvg >= 93 and <= 100:
            return 'A'
        if scoreAvg <= 92.9 and >= 89:
            return 'A-'
        if scoreAvg <= 88.9 and >= 87:
            return 'B+'
        if scoreAvg <= 86.9 and >= 83:
            return 'B'
        if scoreAvg <= 82.9 and >= 79:
            return 'B-'
        if scoreAvg <= 78.9 and >= 77:
            return 'C+'
        if scoreAvg <= 76.9 and >= 73:
            return 'C'
        if scoreAvg <= 72.9 and >= 69:
            return 'C-'
        if scoreAvg <= 68.9 and >= 67:
            return 'D+'
        if scoreAvg <= 66.9 and >= 60:
            return 'D'
        return 'F'

    print(grade(scoreAvg))
    print(studentName, "test score is: ",scoreAvg,'%')


    endProgram = input ('Do you want to restart the program?')

    if endProgram in ('no', 'No', 'NO', 'false', 'False', 'FALSE'):
        break
4

1 に答える 1

5

あなたの質問が何であるかはよくわかりませんが、手紙の等級を取得するより簡潔な方法を次に示します.

>>> scores = [93, 89, 87, 83, 79, 77, 73, 69, 67, 60, 0]
>>> grades = ['A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'D+', 'D', 'F']
>>> 
>>> def gradeFor(s):
...     grade_scores = zip(scores, grades)
...     for score, grade in grade_scores:
...        if s >= score:
...            return grade

>>> gradeFor(87)
B+
>>> gradeFor(89)
A-
>>> gradeFor(88)
B+
>>> gradeFor(67)
D+
>>> gradeFor(72)
C-
>>> gradeFor(40)
F

また、できること

if endProgram.lower() in ('no', 'false'):
于 2013-02-04T06:01:21.157 に答える