Code of the Day

Lab: First steps

Three exercises combining variables, types, conditionals, loops, functions, and lists — all the concepts from the First steps module.

Lab · optionalFirst Steps20 min
By the end of this lesson you will be able to:
  • Use if/elif/else and modulo arithmetic together in a classic problem
  • Write a function that processes a string by splitting it into parts
  • Build a function that finds a maximum value by iterating a list

Optional lab. No new concepts — just hands-on practice with everything from the First steps module. Work through each checkpoint, write code, and hit Check to test yourself. If you get stuck, re-read the relevant lesson.

You have the whole toolkit now: variables, types, conditionals, loops, functions, and lists. This lab puts them together in three small, real tasks. Each one asks you to think about which tools to reach for — and that decision-making is exactly the skill you are building.

Checkpoint 1 — FizzBuzz

FizzBuzz is a classic interview exercise that tests whether you can combine conditionals with arithmetic. The rules:

  • Return 'FizzBuzz' for multiples of both 3 and 5
  • Return 'Fizz' for multiples of 3 only
  • Return 'Buzz' for multiples of 5 only
  • Return the number as a string otherwise

The key insight: check the combined case (n % 3 == 0 and n % 5 == 0) before the individual cases — otherwise 15 would match 'Fizz' first and never reach the 'FizzBuzz' check.

FizzBuzzPython

Write a function fizzbuzz(n) that returns 'FizzBuzz' for multiples of both 3 and 5, 'Fizz' for multiples of 3 only, 'Buzz' for multiples of 5 only, and the number as a string otherwise.

fizzbuzz(15)'FizzBuzz'fizzbuzz(9)'Fizz'fizzbuzz(10)'Buzz'fizzbuzz(7)'7'

Checkpoint 2 — Count words

Many real-world tasks involve processing text. A string's split() method breaks it into a list of words — splitting on whitespace by default. Calling split() on an empty string returns an empty list, not a list with one empty string, so counting words in an empty string naturally gives zero.

Count wordsPython

Write a function count_words(sentence) that returns the number of words in the sentence. A word is any sequence of characters separated by whitespace. An empty string has 0 words.

count_words("hello world")2count_words("")0count_words("one")1

"hello world".split() returns ['hello', 'world']. len() of that list is 2. That is all you need — split already handles multiple spaces and leading/trailing whitespace.

Checkpoint 3 — Maximum of a list

Python has a built-in max() function, but writing your own version is a great way to practise loops and variables. The approach: start by assuming the first element is the maximum, then walk through the rest of the list. If you find something bigger, update your assumption.

Maximum of a listPython

Write a function max_of(nums) that returns the largest number in a non-empty list. Do not use the built-in max() function.

max_of([3, 1, 4, 1, 5])5max_of([-3, -1, -7])-1

Done?

Three green checkpoints means you have used every concept from the First steps module in code that actually works. That is a complete foundation — variables, types, conditionals, loops, functions, and lists. Everything in the Core syntax module ahead builds on exactly these ideas.

Finished reading? Mark it complete to track your progress.

On this page