nerdexam
Python_Institute

PCEP-30-02 · Question #334

You are designing a decision structure to convert a student's numeric grade to a letter grade. The program must assign a letter grade as specified as followed: 90 through 100 -> A 80 through 89 -> B…

The correct answer is A. if grade >= 90: elif grade >= 80: elif grade >= 70: elif grade >= 65. Option A is correct because using >= (greater than or equal to) with descending thresholds correctly captures each grade range. Since Python's if/elif chain stops at the first true condition, checking grade >= 90 first handles the A range, then grade >= 80 catches everything…

Question

You are designing a decision structure to convert a student's numeric grade to a letter grade. The program must assign a letter grade as specified as followed: 90 through 100 -> A 80 through 89 -> B 70 through 79 -> C 65 through 69 -> D 0 through 64 -> F For example, if the user enters a 90, the output should be Your letter grade is A. Likewise, if a user enters an 89, the output should be Your letter grade is B. Consider the code below. Which of the following code blocks should you insert on Line-3, Line-5, Line-7 and Line-9 to correctly implement the grade conversion logic?

Letter Grade Converter

grade = int(input('Enter a numeric grade:'))

Line-3

letter_grade = 'A'

Line-5

letter_grade = 'B'

Line-7

letter_grade = 'C'

Line-9

letter_grade = 'D' else: letter_grade = 'F' print('Your letter grade is:', letter_grade)

Options

  • Aif grade >= 90: elif grade >= 80: elif grade >= 70: elif grade >= 65:
  • Bif grade > 90: elif grade > 80: elif grade > 70: elif grade > 65:
  • Cif grade < 90: elif grade < 80: elif grade < 70: elif grade < 65:
  • Dif grade <= 90: elif grade <= 80: elif grade <= 70: elif grade <= 65:

How the community answered

(16 responses)
  • A
    81% (13)
  • C
    6% (1)
  • D
    13% (2)

Explanation

Option A is correct because using >= (greater than or equal to) with descending thresholds correctly captures each grade range. Since Python's if/elif chain stops at the first true condition, checking grade >= 90 first handles the A range, then grade >= 80 catches everything from 80–89 (because anything ≥90 was already handled), and so on down the chain - the else at the end cleanly catches 0–64 as F.

Option B fails because grade > 90 excludes exactly 90, meaning a student who earns a 90 would incorrectly receive a B instead of an A - the same off-by-one error applies at every boundary (80, 70, 65).

Options C and D fail because the logic is inverted: < and <= conditions with a top-down chain would match the wrong students first - for instance, grade < 90 is true for most grades, so nearly everyone would get an A, and the lower elif branches would rarely or never be reached.

Memory tip: Think "highest first, greater-or-equal always" - start your chain at the top grade boundary (90), use >= to include the boundary itself, and let the elif structure do the narrowing work for you automatically.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice