def counter(start, stop):
if start > stop:
return_string = "Counting down: "
while ___ # Complete the while loop
___ # Add the numbers to the “return_string”
if start > stop:
return_string += “,”
___ # Increment the appropriate variable
else:
return_string = "Counting up: "
while ___ # Complete the while loop
___ # Add the numbers to the “return_string”
if start < stop:
return_string += “,”
___ # Increment the appropriate variable
return return_string
print(counter(1, 10)) # Should be “Counting up: 1,2,3,4,5,6,7,8,9,10”
print(counter(2, 1)) # Should be “Counting down: 2,1”
print(counter(5, 5)) # Should be “Counting up: 5”
Looks like you’re doing pretty well so far, you have 50% of the code already. You just need to fill in the last few missing bits and test it to be sure it works.
If you are having trouble, I suggest you start by working through the process with pen and paper.
counter(2, 1)
we have start=2 and end=1
so `return_string = "Counting down: "
what needs to be appended to the end of the string next?
how do you do that?
Hint: you can’t add numbers to strings, but you can call str(number) to convert to a string first.