Professional Documents
Culture Documents
Minor Project (Kartik Joshi)
Minor Project (Kartik Joshi)
import time
class Countdown:
def __init__(self):
self.start_time = 0
self.remaining = 0
self.thread = None
self.active = False
self.paused = False
if self.active:
return
self.start_time = seconds
self.remaining = seconds
self.active = True
self.paused = False
self.thread = threading.Thread(target=self._run)
self.thread.start()
def _run(self):
if not self.paused:
time.sleep(1)
self.remaining -= 1
if self.remaining == 0:
print("\nDone!")
self.active = False
def pause(self):
return
self.paused = True
def resume(self):
if not self.paused:
return
self.paused = False
def reset(self):
self.active = False
self.paused = False
self.remaining = self.start_time
def stop(self):
if not self.active:
return
self.active = False
self.paused = False
# Create an instance of the Countdown class and start the countdown with the user's input
countdown = Countdown()
countdown.start(duration)
# To control the countdown dynamically, consider implementing a way to call pause(), resume(), reset(),
and stop() based on user input.