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
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!')
Comments
Your page is helping me a lot
Leave a comment