1
1
Fork 0
PythonLearning/blastoff/main.py

33 lines
1.7 KiB
Python
Raw Normal View History

from time import (
sleep, #the sleep function adds a delay, allowing time to tick down by a second rather than instantly
)
sleep # the sleep function adds a delay, allowing time to tick down by a second rather than instantly
2024-04-29 18:46:36 -04:00
def countdown(n: int) -> None:
if n <= 0: #If a number is less than or equal to 0,
print('Blastoff!') #Blastoff! is printed, else
2024-04-29 18:46:36 -04:00
else:
print(n) #we print the current number inputted,
sleep(1) #The code is delayed by a second to replicate an actual countdown
countdown(n-1) #The code deducts 1 from our inputted number, until it reaches 0.
2024-04-29 19:20:03 -04:00
def countup(n: int) -> None:
if n >= 0: #we're definining the countup function, if a number is 0 or greater
print('Blastoff!') #if the above condition is met, Blastoff! is printed, else
2024-04-29 18:46:36 -04:00
else:
print(n) #we print the number
sleep(1) #delay the code by a second to match an actual countdown(countup in this instance)
countup(n+1) #We add 1 to our number, since with a countup, we'll be dealing with negatives going towards 0
2024-04-29 18:46:36 -04:00
def count(n: int) -> None: #this part of the code checks to see if a number is positive or negative
if int(n) >= 0: #We're checking for if a positive number is inputted, or negative
countdown(n) #If positive, we'll utilize the Countdown function
2024-04-29 18:46:36 -04:00
else:
countup(n) #If negative, we'll utilize the countup function
2024-04-29 18:46:36 -04:00
if __name__ == "__main__":
num = input("Enter a number: ")
2024-04-29 19:20:03 -04:00
count(int(num))