A for loop visits every item in a sequence once. A score list, a word, or range(5) all use the same shape. You do not advance a counter. Python stops when the items run out.
This guide covers a for over a list, range when you need the index, then the same scores mapped to letters with if. Paste the code into the online Python compiler and read the output. Then write it as a function in Letter Grades.
for over a list
scores = [95, 82, 70, 55, 49]
for score in scores:
print(score)
score is the next number on each turn: 95, then 82, and finally 49. When the list ends, the loop ends. score keeps the last value. It does not start another pass.
range when you need the index
scores = [95, 82, 70]
for i in range(len(scores)):
print(i, scores[i])
range(3) yields 0, 1, 2. Indexes start at 0. scores[3] raises IndexError on this list.
If you need both the index and the value, enumerate is shorter:
for i, score in enumerate(scores):
print(i, score)
for and if: a score becomes a letter
for brings the next score. if picks one letter.
scores = [95, 82, 70, 55, 49]
for score in scores:
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(score, letter)
Output:
95 AA
82 BA
70 BB
55 CC
49 FF
95 also satisfies >= 80. It stays AA because >= 90 is tested first. Reverse the branches and 95 becomes BA. Tighter bounds go above wider ones.
print inside the loop writes one line per score. A print after the loop shows only the last letter.
What usually breaks
- Indentation. Lines that belong to the
formove in together. No indent raisesIndentationError. - Appending to the list you are walking.
scores.append(...)insidefor score in scoresextends the trip. Collect results in a new list. range(1, len(scores))skips the first item. Start at 0 unless you mean to skip it.
To walk the same list with a counter, read the while loop guide. Condition order is in if, elif, else.
Write it as the problem
Letter Grades uses this scale. print is not enough. Return a list with the same length and the same order as the input.
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
An empty list never enters the loop, so the function returns []. That matches the empty-input rule. Try print(harf_notlari([95, 82, 49])) on the online Python page, then 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 if, elif, else: Condition Order and Letter Grades
Python if, elif, and else run the first true branch. Test 80 before 90 and a score of 95 becomes BA. The Letter Grades problem checks this order.
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.