Answer to Question #274935 in Python for kika

Question #274935

Write a new recursive function count up that expects a negative argument and counts “up” from that number.


1
Expert's answer
2021-12-05T02:15:32-0500
Source Code
 
#define count down function
 def countdown(n):
 
   if n <= 0:
 
     print('Blastoff!')
 
   else:
 
     print(n)
 
     countdown(n-1)
 
 #define the countup function
 def countup(n):
 
   if n >=0:
 
     print('Blastoff!')
   else:
 
     print(n)
 
     countup(n+1)
 
 #main
 
 number=int(input("Enter a number: "))
 
 if number>0:
    print(countdown(number))
 
 elif number<0:
    print(countup(number))
 
 elif number==0:
    print(countup(number))
 

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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS