Answer to Question #237959 in Python for Joel

Question #237959

1. Copy the countdown function from Section 5.8 of your textbook.


def countdown(n):

   if n <= 0:

     print('Blastoff!')

   else:

     print(n)

     countdown(n-1)



Write a new recursive function countup that expects a negative argument and counts “up” from that number. Output from running the function should look something like this:

>>> countup(-3)

-3

-2

-1




1
Expert's answer
2021-09-17T17:17:50-0400
import sys
def countdown(n):
  if n <= 0:
    print('Blastoff!')
  else:
    print(n)
    countdown(n-1)
    
def countup(n):
  if n >= 0:
    print('Blastoff!')
  else:
    print(n)
    countup(n+1)
 
if sys.version_info[0] == 5:
  number = int(input('Enter a negative interger: '))
else:
  number = int(input('Enter an negative interger: '))


if number> 0:
  countdown(number)
elif number < 0:
  countup(number)
else:
  print('Blastoff!')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Daniel James Dugah
25.09.23, 12:07

Your page is helping me a lot

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS