Skip to content

Practice module 6

>Practice Projects: coding practice

Start with the lesson drills, then combine the ideas in the module labs. Every task has automatic checks, progressive hints, reset and a solution.

Module coding progress8 exercises available

Lesson coding drills

One focused editor exercise for every lesson in this module. (0/4 passed this visit)

You can run every exercise now. Create a free ID to keep passes, code attempts and XP.

Lesson 1: Project: Number Guessing Game

Not passed yet

Make a deterministic guessing check. Set secret to 5, use guesses = [3, 5], and count guesses in attempts. Print each guess as Guess: number. When the secret is found, print Correct!, then print Attempts: 2.

# Create the secret and the list of guesses
# Use a while loop to check the guesses

Lesson 2: Project: Tip and Bill Splitter

Not passed yet

Set bill to 36.0, tip_rate to 0.15, and people to 3. Calculate rounded variables named total and share. Print exactly:
Total: $41.40
Each person pays: $13.80

# Set bill, tip_rate, and people
# Calculate total and share, then print both values

Lesson 3: Project: Word Statistics Tool

Not passed yet

Set text to "cat dog cat bird". Build a dictionary named counts, then a list named top_words sorted by count descending and word ascending. Print exactly:
Top words:
cat: 2
bird: 1
dog: 1

# Create text and split it into words
# Count words and create the sorted top_words list

Lesson 4: Project: To-Do List Manager

Not passed yet

Create a Task class with title, done, and __str__ that returns [x] title when done and [ ] title otherwise. Create a TodoList class with add and complete methods. Add Plan trip, complete it, and print exactly [x] Plan trip.

# Define Task and TodoList
# Add and complete the requested task

Coding practice: write it yourself

Real Python, real checks: write your answer, press Run checks, and keep going until it passes. (0/4 passed this visit)

You can run every exercise now. Create a free ID to keep passes, code attempts and XP.

Lab 1: Tip and split

Not passed yet

Dinner is 2400 taka with a 10% service charge, shared by 4 people. Print each person's share rounded to 2 decimals.

bill = 2400
service_pct = 10
people = 4
# compute total, then per-head share

Lab 2: Word counter

Not passed yet

Count the words in "practice makes perfect every day".

text = "practice makes perfect every day"
# print the number of words

Lab 3: Pending tasks

Not passed yet

Given the tasks list below, print how many are NOT done.

tasks = [
    {"title": "Homework", "done": True},
    {"title": "Buy eggs", "done": False},
    {"title": "Call aunt", "done": False},
]
# print the pending count

Lab 4: Vowel census

Not passed yet

Count the vowels (a, e, i, o, u) in "learning python".

text = "learning python"
# print the vowel count

References & Further Reading

Related entries from PyLabs's own reference library.

  • input() (Read a line of text typed by a user.)
  • get() (Look up a value safely without raising a KeyError if missing.)
  • copy() (Make a shallow copy of a list.)