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.
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.
More Python Guides & Articles
Python for Loop: Lists, range, and Letter Grades
A Python for loop walks every item in a list. range, indexes, and turning scores into letter grades. The Letter Grades problem uses the same scale.
Python Data Structures Guide: Stacks, Trees, and Graphs with Interactive Interview Problems
Master stacks (monotonic stack, heaps), binary trees (BST, DFS, BFS), and graphs (topological sort, Dijkstra) in Python with clean code templates and 30+ interactive interview challenges.
Python while Loop: Counter, Condition, and a Score List
A Python while loop repeats while its condition stays true. Counters, infinite loops, and walking a score list by index. The same scale is the Letter Grades problem.
10 Core Algorithms Every Python Developer Should Know to Become an AI Engineer (2026)
From cosine similarity to BPE tokenization, BM25 to beam search: learn the 10 core algorithms that power LLM and RAG systems and show up in AI engineering interviews, implemented in pure Python.
Best Python Courses for Intermediate Learners: Udemy, Coursera & Book Recommendations (2026)
Curated 10-minute guide to the best Python courses for intermediate learners in 2026. Compare top Udemy deep-dives, Coursera specializations, must-read Python books, and an 8-week study roadmap.
Python Intermediate Level Project Ideas: 8 Portfolio-Ready Engineering Projects (2026)
Stop building basic calculators and to-do apps. Explore 8 intermediate level Python project ideas with working code architectures, async pipelines, custom data structures, and interview-ready system designs.
Most Asked Python Interview Questions and Answers (2026)
The most frequently asked technical Python interview questions, tricky output puzzles, and working code examples. Read this complete guide from junior to senior level before your interview.