LearnFrenzy
Sign in Take a free test

Loops · Exercise 4 of 4

Loops Loops Coding Problems

  • 10 questions
  • Page 1 of 1
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Classic Python loop programs asked in practicals and placement tests. Write each one yourself first, then open the solution – every solution was run on Python 3, the output shown is the real output, and Run opens it in the online Python compiler.

Question 1 Easy

Print the first 12 terms of the Fibonacci series, starting 0, 1.

Question page & discussion
Question 2 Medium

Find the GCD of each pair with a while loop (Euclid's algorithm), then the LCM, and check against math.gcd.

Question page & discussion
Question 3 Medium

Print all three-digit Armstrong numbers – numbers equal to the sum of the cubes of their digits.

Question page & discussion
Question 4 Medium

Print a centred number pyramid of 5 rows, where row i counts up from 1 to i and back down to 1.

Question page & discussion
Question 5 Easy

Print Floyd's triangle with 5 rows: consecutive numbers, one in the first row, two in the second, and so on.

Question page & discussion
Question 6 Medium

Print the Collatz sequence of 6 and of 27's step count: halve an even number, replace an odd number with 3n + 1, until reaching 1.

Question page & discussion
Question 7 Easy

Count the vowels, consonants, digits and spaces in a sentence with a single loop.

Question page & discussion
Question 8 Medium

The secret number is 37. Read guesses (one per line) and reply "higher" or "lower", allowing at most 5 attempts; congratulate on a correct guess, or reveal the number after 5 misses.

Question page & discussion
Question 9 Hard

Find the perfect numbers below 10,000 – numbers equal to the sum of their proper divisors – checking divisors only up to √n.

Question page & discussion
Question 10 Easy

Print a 6 × 6 multiplication grid with a header row and a header column.

Question page & discussion
All exercises doneBack to LoopsRevise the concepts or pick another topic

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links