Skip to content

Commit 24a7c96

Browse files
authored
Merge pull request sumanth-0#715 from sumanth-0/fix-issue-time
Fix: resolved issue sumanth-0#7 (description of fix)
2 parents 73b0c53 + 87b2c7b commit 24a7c96

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

countdown_timer/countdown_timer.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
Countdown Timer
3+
Displays a countdown in minutes and seconds in the terminal.
4+
"""
5+
6+
import time
7+
8+
def countdown(minutes):
9+
total_seconds = minutes * 60
10+
try:
11+
while total_seconds >= 0:
12+
mins, secs = divmod(total_seconds, 60)
13+
timer = f"{mins:02d}:{secs:02d}"
14+
print(f"\r⏱️ {timer}", end="")
15+
time.sleep(1)
16+
total_seconds -= 1
17+
print("\n✅ Time's up!")
18+
except KeyboardInterrupt:
19+
print("\n⏸️ Countdown stopped by user.")
20+
21+
def main():
22+
print("\n⏳ Countdown Timer ⏳")
23+
while True:
24+
print("\nMenu:")
25+
print("1️⃣ Start Countdown")
26+
print("2️⃣ Exit")
27+
choice = input("Choose an option (1-2): ").strip()
28+
if choice == "1":
29+
try:
30+
minutes = int(input("Enter time in minutes: ").strip())
31+
if minutes > 0:
32+
countdown(minutes)
33+
else:
34+
print("Please enter a positive number.")
35+
except ValueError:
36+
print("Invalid input. Please enter an integer.")
37+
elif choice == "2":
38+
print("Goodbye! ⏱️")
39+
break
40+
else:
41+
print("Invalid option. Try again!")
42+
43+
if __name__ == "__main__":
44+
main()

countdown_timer/readme.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# ⏳ Countdown Timer
2+
3+
**Countdown Timer** is a simple Python script that displays a countdown in minutes and seconds in the terminal.
4+
It updates every second and notifies you when the time is up.
5+
6+
---
7+
8+
## Features
9+
10+
- ⏱️ Countdown in **minutes and seconds**
11+
- Updates **every second** in the terminal
12+
- Graceful handling of **Ctrl+C** to stop the timer
13+
- Interactive menu for easy use
14+
15+
---
16+
17+
## Getting Started
18+
19+
1. **Install Python 3**
20+
2. Save `countdown_timer.py` in a folder
21+
3. Run the script:
22+
```bash
23+
python countdown_timer.py
24+
25+
⏳ Countdown Timer ⏳
26+
27+
Menu:
28+
1️⃣ Start Countdown
29+
2️⃣ Exit
30+
Choose an option (1-2): 1
31+
Enter time in minutes: 1
32+
⏱️ 01:00
33+
⏱️ 00:59
34+
⏱️ 00:58
35+
...
36+
⏱️ 00:01
37+
✅ Time's up!

0 commit comments

Comments
 (0)