ΣνΜDr. Sharon's Math PlatformSyvara Learning
Question Bank › 📘 Undergraduate › Programming for Engineers › Q12

Q12 · The code below should count numbers greater than 5 in [2, 4, 5, 7, 8, 10, 13] but has…

Error Handling and Debugging 🟡 Intermediate Coding
Question

The code below should count numbers greater than 5 in [2, 4, 5, 7, 8, 10, 13] but has two bugs:

  numbers = [2, 4, 5, 7, 8, 10, 13]
  count = 1
  for num in numbers:
      if num <= 5:
          count += 1
  print("Number of numbers greater than 5:", count)

(a) Add print statements to trace num, the condition result, and count at each step.
(b) Identify both bugs.
(c) Fix the code. The correct answer is 4.

🔒

Log in to see the worked solution

Enter your email to get started. Your first free solutions in every course unlock as soon as you verify.

Log in or sign up with email
← Previous Next →
Working…