Write a new recursive function count up that expects a negative argument and counts “up” from that number.
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))
Comments
Leave a comment