Going through the list
Section 5: ListsLesson 5.2 · ⏱ 7 min
scores = [7, 9, 4, 10]
for s in scores:
print("Score:", s)
print("Best:", max(scores))
print("Total:", sum(scores))
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗Score: 7 Score: 9 Score: 4 Score: 10 Best: 10 Total: 30

📌 Another example: counting in the list
We count how many numbers are bigger than 50.
marks = [45, 80, 62, 30, 95]
count = 0
for m in marks:
if m > 50:
count = count + 1
print(count, "passed")
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗3 passed
✍️ Practise
Try the lesson's examples here: copy the code, change it, and click ▶ Run.
✍️ Practise here in the lesson✖ Close the labor open the lab in a new page ↗
🎯 Challenge yourself
Easy
Print every name in the list with Hi.
👀 Show the solution🙈 Hide the solution
names = ["Ali", "Mona", "Omar"]
for n in names:
print("Hi", n)
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗Hi Ali Hi Mona Hi Omar
Result: Hi Ali, Hi Mona, Hi Omar
Medium
Print every word with its number of letters.
👀 Show the solution🙈 Hide the solution
words = ["sun", "moon", "star"]
for w in words:
print(w, len(w))
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗sun 3 moon 4 star 4
Result: sun 3, moon 4, star 4
Hard
A new list with double each number.
👀 Show the solution🙈 Hide the solution
nums = [1, 2, 3, 4]
doubled = []
for n in nums:
doubled.append(n * 2)
print(doubled)
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗[2, 4, 6, 8]
Result: [2, 4, 6, 8]

