Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions