Exercises on Control Flow
The solutions for the exercises are included in the solution tabs. For best learning outcomes, don’t look at these unless you’ve attempted the problems yourself.
Question 1: FizzBuzz
Write a program that prints the numbers from 1 to 100 with the following exceptions:
- For multiples of 3, print ‘Fizz’ instead of the number.
- For multiples of 5, print ‘Buzz’ instead of the number.
- For numbers that are multiples of both 3 and 5, print ‘FizzBuzz’ instead.
Try solving here:
Question 2: Newton’s method
Write a program to estimate the square root of 612 using Newton’s method, using five iterations.
Try solving here:
Question 3: Display triangle
Write a program that displays a triangle with height and base width .
The expected output for would be a triangle with height and a base width :
If you’re unsure how to do this, click the “Show Hint” button.
Try solving here:
If you’re stuck, click the “Show Solution” button.
Exercises on Control Flow
The solutions for the exercises are included in the solution tabs. For best learning outcomes, don’t look at these unless you’ve attempted the problems yourself.
Question 1: FizzBuzz
Write a program that prints the numbers from 1 to 100 with the following exceptions:
- For multiples of 3, print ‘Fizz’ instead of the number.
- For multiples of 5, print ‘Buzz’ instead of the number.
- For numbers that are multiples of both 3 and 5, print ‘FizzBuzz’ instead.
Try solving here:
Question 2: Newton’s method
Write a program to estimate the square root of 612 using Newton’s method, using five iterations.
Try solving here:
Question 3: Display triangle
Write a program that displays a triangle with height and base width .
The expected output for would be a triangle with height and a base width :
If you’re unsure how to do this, click the “Show Hint” button.
Try solving here:
If you’re stuck, click the “Show Solution” button.