Quick Thought
This lesson isn't about learning something new — it's meant as a self-test of the variables, data types, strings, lists, loops, and functions you covered in the Basics chapter. Writing and running the code for each task yourself will help these concepts really stick. If you get stuck, feel free to go back and review earlier lessons. The goal isn't to copy the correct answer straight down, but to practice working through the logic yourself.
Exercises
Task 1: Take the user's name and age with input() and print a sentence like "Hi <name>, you are <age> years old". Task 2: Take a string and count how many vowels (a, e, i, o, u) it contains in total. Task 3: Given a list of numbers, filter out just the even numbers into a new list. Task 4 (bonus): Using a loop, print every number from 1 to 50 that's divisible by 3.
Sample Code
# Task 1: Greeting
name = input("Enter your name: ")
age = input("Enter your age: ")
print(f"Hi {name}, you are {age} years old")
# Task 2: Count vowels
def count_vowels(text):
vowels = "aeiouAEIOU"
count = 0
for ch in text:
if ch in vowels:
count += 1
return count
print(count_vowels("Python Programming"))
# Task 3: Filter even numbers
numbers = [4, 7, 2, 9, 10, 15, 6]
evens = [n for n in numbers if n % 2 == 0]
print(evens)
# Task 4 (bonus): multiples of 3
for i in range(1, 51):
if i % 3 == 0:
print(i)If you complete every task correctly, the terminal will show the greeting sentence, the vowel count, the filtered list of even numbers, and the list of numbers between 1 and 50 that are divisible by 3.Try It: 5 Minutes
Set a 5-minute timer and write Task 1 and Task 2 yourself, without peeking at the reference code.
A Quick Warning
When you practice, try to work through it yourself first instead of jumping straight to the solution. Reading error messages and debugging is itself a genuinely important skill.