Complete in python3 , I know how to start a countdown but im having trouble displaying the word instead of zero
Countdown
Write a function as follows.
* function name: countdown
* parameters: start (int)
whoopee_word (string)
* returns: N/A
* operation:
Count down from start to 1. Instead of 0, print the
whoopee_word.
BUT:
- If start is less than 1 or greater than 20, print "start is out
of range"
and exit the function
- If start is not an int, print "invalid start parameter" and exit
(easy way
to do this is to use exception handling around your range()
function if you
use a for loop)
- If whoopee_word is not provided (is None or an empty string) then
just assume
the whoopee_word should be "BLASTOFF"
* expected output:
>>> countdown(5,"Light this candle!")
5
4
3
2
1
Light this candle!
>>> countdown(7)
7
6
5
4
3
2
1
BLASTOFF
>>> countdown(-1,"GO")
start is out of range
>>> countdown("TEN","BOING!!")
invalid start parameter
If you have any doubts, please give me comment...
import sys
def countdown(start, whoopee_word="BLASTOFF"):
if type(start) is str:
print("invalid start parameter")
sys.exit(0)
if start<1 or start>20:
print("start is out of range")
sys.exit(0)
for i in range(start, 0, -1):
print(i)
print(whoopee_word)
countdown(5, "Light this candle!")
countdown(7)
Get Answers For Free
Most questions answered within 1 hours.