Looping over text
Python · Unit 6: Strings
- Full plan
- Python
- 10 exercises
A for goes through a string letter by letter, just like it goes through a list.
Spaces and punctuation get their own round too.
for letter in "sun":
print(letter)Prints
s u n
The rest of the explanation is in the lesson, which is part of the full plan.
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Predict the output
What does this code print?
2. Predict the output
What does this code print?
3. Predict the output
What does this code print?
4. Complete the code
Complete the function that counts the vowels in a string.
5. Find the case that fails
count_a(text)should count how manyathe text has, uppercase or lowercase. Which call breaks it?6. Predict the output
What does this code print?
7. Find the bug
This program should remove the spaces and print "helloworld". Which line has the error?
8. Multiple choice
What does this function do?
9. Put the lines in order
Order the function that hides the vowels with
*.10. Predict the output
What does this code print?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.