WEB PRACTICE W031Count vowels
Count the vowels in an example sentence.
Reveal a hint
Make the text lowercase first.
Reveal example code (after trying it yourself)
text = "Programming is creative"
vowels = sum(1 for c in text.lower() if c in "aeiou")
print("Vowels:", vowels)
One possible solution. Try writing your own first.
Extension: Change the sample values and test at least two different cases.
WEB PRACTICE W032Reverse a name
Reverse the letters of the word Python.
Reveal a hint
Try slicing with a step of -1.
Reveal example code (after trying it yourself)
word = "Python"
print(word[::-1])
One possible solution. Try writing your own first.
Extension: Change the sample values and test at least two different cases.
WEB PRACTICE W033Initials generator
Create initials for the name Ada Lovelace.
Reveal a hint
Split the name at spaces.
Reveal example code (after trying it yourself)
name = "Ada Lovelace"
initials = "".join(part[0].upper() for part in name.split())
print(initials)
One possible solution. Try writing your own first.
Extension: Change the sample values and test at least two different cases.
WEB PRACTICE W034Trim spaces
Clean extra spaces around a typed answer and lower-case it.
Reveal a hint
Use strip() and lower() together.
Reveal example code (after trying it yourself)
answer = " YeS "
cleaned = answer.strip().lower()
print(cleaned)
One possible solution. Try writing your own first.
Extension: Change the sample values and test at least two different cases.
WEB PRACTICE W035Simple palindrome
Check whether racecar reads the same backwards.
Reveal a hint
Compare the string with its reverse.
Reveal example code (after trying it yourself)
word = "racecar"
print("Palindrome" if word == word[::-1] else "Not palindrome")
One possible solution. Try writing your own first.
Extension: Change the sample values and test at least two different cases.
WEB PRACTICE W036Count words
Count the words in an example sentence.
Reveal a hint
split() creates a list of words.
Reveal example code (after trying it yourself)
sentence = "Python helps me solve problems"
print("Word count:", len(sentence.split()))
One possible solution. Try writing your own first.
Extension: Change the sample values and test at least two different cases.
WEB PRACTICE W037Replace a word
Replace a placeholder in a sentence with the word Python.
Reveal a hint
Use string replace().
Reveal example code (after trying it yourself)
message = "I enjoy SUBJECT lessons."
print(message.replace("SUBJECT", "Python"))
One possible solution. Try writing your own first.
Extension: Change the sample values and test at least two different cases.
WEB PRACTICE W038Mask a code
Show the final four characters of a sample reference code.
Reveal a hint
Slicing with [-4:] takes the last four.
Reveal example code (after trying it yourself)
reference = "ABCDEF4826"
print("Reference ending:", reference[-4:])
One possible solution. Try writing your own first.
Extension: Change the sample values and test at least two different cases.
WEB PRACTICE W039Count letters
Count the number of letter a characters, ignoring case.
Reveal a hint
Use lower() and count().
Reveal example code (after trying it yourself)
text = "Amazing Adventures"
print("a letters:", text.lower().count("a"))
One possible solution. Try writing your own first.
Extension: Change the sample values and test at least two different cases.
WEB PRACTICE W040Alphabetic characters
Extract alphabetic characters from a mixed string.
Reveal a hint
Use isalpha() in a loop.
Reveal example code (after trying it yourself)
text = "Py3thon! 2026"
letters = "".join(c for c in text if c.isalpha())
print(letters)
One possible solution. Try writing your own first.
Extension: Change the sample values and test at least two different cases.