if asks one question. If the answer is true, its block runs. If not, that block is skipped. A score has one letter, so elif asks the next question, and else covers whatever is left.

Letter grades are that pattern in interview form. The scale is fixed. The wrong order produces the wrong letter. Run the code on the online Python page, then return the list from Letter Grades.

One question

score = 95
if score >= 90:
    print("AA")

95 is at least 90, so this prints AA. A score of 70 skips the block and prints nothing. else is how you say what happens when the condition fails.

score = 70
if score >= 90:
    print("AA")
else:
    print("not AA")

Several bounds: elif

One score can match more than one test. 95 is >= 90, >= 80, and >= 50. Python stops at the first true branch.

score = 95
if score >= 90:
    letter = "AA"
elif score >= 80:
    letter = "BA"
elif score >= 70:
    letter = "BB"
elif score >= 60:
    letter = "CB"
elif score >= 50:
    letter = "CC"
else:
    letter = "FF"
print(letter)

The first condition matches, so the letter stays AA.

Score First match Letter
95 >= 90 AA
82 >= 80 BA
70 >= 70 BB
55 >= 50 CC
49 none FF

Break the order:

score = 95
if score >= 80:
    letter = "BA"
elif score >= 90:
    letter = "AA"

95 matches >= 80, so the letter is BA. The >= 90 branch never runs. The tighter bound goes above the wider one.

80 <= score < 90 is also correct. Those ranges do not overlap, so order is less of a trap. Overlapping >= tests make order your job.

One letter per score

A single score is not the problem. A list means you ask the same questions for every item. The loop is a for or a while. The branch that picks the letter stays the same.

scores = [95, 82, 49]
for score in scores:
    if score >= 90:
        letter = "AA"
    elif score >= 80:
        letter = "BA"
    elif score >= 50:
        letter = "CC"
    else:
        letter = "FF"
    print(score, letter)

Separate if blocks, with no elif, can print more than one letter for 95. Use elif when you want one letter.

Indentation says which block a line belongs to. A print aligned with the if and inside the for runs once per turn. A print inside the if runs only when that branch matches.

Write it as the problem

Letter Grades wants the full scale: AA, BA, BB, CB, CC, FF. The return value is a list, not printed lines.

def harf_notlari(notlar: list[int]) -> list[str]:
    result = []
    for score in notlar:
        if score >= 90:
            result.append("AA")
        elif score >= 80:
            result.append("BA")
        elif score >= 70:
            result.append("BB")
        elif score >= 60:
            result.append("CB")
        elif score >= 50:
            result.append("CC")
        else:
            result.append("FF")
    return result

70 is BB. If you get CB, the >= 70 branch is missing or a wider branch sits above it. 90 is AA. If you get BA, >= 90 is below >= 80.

Run print(harf_notlari([95, 82, 70, 55, 49])) on the online Python page. When the list is ["AA", "BA", "BB", "CC", "FF"], open the problem.

Interactive Practice Station

Ready to Test Theory in a Real Exam Environment?

10 specialization modules and 200 original Python interview problems await you on PyMülakat. Write and run your code in the browser and test yourself against hidden boundary cases.

Solve First Problem (K01) →Explore Modules