Computer Science, asked by bhagyashrimulik41220, 7 months ago

5.
The counter function counts down from start to stop when start is bigger than stop, and counts up from start to
stop otherwise. Fill in the blanks to make this work correctly.
9
I
1 - def counter(start, stop):
2 x = start
3 -
if :
4
return_string = "Counting down:
5 -
while x >= stop:
6
return_string += str(x)
7-
if :
8
return_string +=
9
10 else:
11 return_string
*Counting up:
12 - while x <= stop:
13
return_string += str(x)
14 -
if :
15
return_string + =
16
17 return return_string
18
19 print(counter(1, 10)) # Should be "Counting up: 1,2,3,4,5,6,7,8,9,10"
20 print(counter(2, 1)) # Should be "Counting down: 2,1"
21
print(counter(5.5)) # Should be "Counting up: 5"

Answers

Answered by paavansharma789
35

Answer:

def counter(start, stop):

x = start

if x>stop:

 return_string = "Counting down: "

 while x >= stop:

  return_string += str(x)

  if x>stop :

   return_string += ","

  x=x-1

else:

 return_string = "Counting up: "

 while x <= stop:

  return_string += str(x)

  if x<stop:

   return_string += ","

  x=x+1

return return_string

Explanation:

Answered by himanshuneha0304
0

Answer:

def counter(start, stop):

   x = start

   if start > stop:

       return_string = "Counting down: "

       while x >= stop:

           return_string += str(x)

           x = x-1

           if start != stop:

               return_string += ","

       print()

   else:

       return_string = "Counting up: "

       while x <= stop:

           return_string += str(x)

           x = x + 1

           if start != stop:

               return_string += ","

       print()

   return return_string

Explanation:

Similar questions