In this code, there's an initialization problem that's causing our function to behave incorrectly. Can you find the problem and fix it?

Question:

def count_down(start_number):
  while (current > 0):
    print(current)
    current -= 1
  print("Zero!")

count_down(3)
Asked By: Fuad_Hasan_Emon

||

Answers:

Running the code reveals exactly where the problem is:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in count_down
UnboundLocalError: local variable 'current' referenced before assignment
Answered By: Samwise

Instead of current use start_number

 def count_down(start_number):
      while (start_number > 0):
        print(start_number)
        start_number -= 1
      print("Zero!")
    
    count_down(3)

output:
        3
        2
        1
        Zero!
Answered By: Zesty Dragon
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.