import sys
# count down function
def countdown(n):
if n <= 0:
print('Blastoff!')
else:
print(n)
countdown(n-1)
# count up function
def countup(n):
if n >= 0:
print('Blastoff!')
else:
print(n)
countup(n+1)
# ask user to enter number
if sys.version_info[0] == 3:
num = input('Enter number: ')
else:
num = raw_input('Enter number: ')
# convert string to number
num = int(num)
if num > 0:
# count down positive number
countdown(num)
elif num < 0:
# count up negative number
countup(num)
else:
# there is no difference which function to call
# in case of 0, both functions will print 'Blastoff!'
print('Blastoff!')
# Outputs:
# num=3 3 2 1 Blastoff!
# num=-3 -3 -2 -1 Blastoff!
# num=0 Blastoff!
Comments
This website is very helpful. I can learn about coding and how to create a full program. It is a very good website.
I love this site and will like to remain on it all the time just for exploits for better understanding.
Leave a comment