Embercode
✕
LoopsQuick quiz

Iteration forms

7 questions. Covers Sentinel loops with input in Python.

Questions 1 to 5 of 7

  1. 1. What does this program print? ``python nums = [4, 5, 6] for x in nums: x += 1 total = 0 for x in nums: total += x print(total) ``
  2. 2. What does this program print? ``python stock = {"pear": 3, "apple": 7, "fig": 0} total = 0 for n in stock.values(): total += n print(total) ``
  3. 3. The loop below raises an error. What is the bug? ``python stock = {"pear": 3, "apple": 7, "fig": 0} total = 0 for n in stock: total += n print(total) ``
  4. 4. This program reads numbers until 0 and prints their average. It is run with the input 0 alone. What is the bug? ``python total = 0 count = 0 x = int(input()) while x != 0: total += x count += 1 x = int(input()) print(total / count) ``
  5. 5. Which value can a Python for loop not read from directly?

5 question(s) left on this page.