Question
Create a recursive function based upon the countdown function from the text called timer that waits 1 second for each count and prints a message
Create a recursive function based upon the countdown function from the text called timer that waits 1 second for each count and prints a message when the countdown expires. If the timer value is 0 or negative, print an error message and return without doing anything. Assume all inputs will be integer values.
TO BE DONE ON "PYTHON"
Sample output:
timer(5) 5 <1 sec pause> 4 <1 sec pause> 3 <1 sec pause> 2 <1 sec pause> 1 <1 sec pause> Timer Done
I have this code, but i cannot print an error message when i print "ZERO". Please show solution under "ONE FUNCTION" only.
import time
def timer(n): if n<=0: print('Timer Done') else: print(n) time.sleep(1) n-=1 return timer(n) timer(2)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started