Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions subh.ftg
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Countdown time in Python





Comment on lines +2 to +6

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary empty spaces

import time

def countdown(time_sec):
while time_sec:
mins, secs = divmod(time_sec, 60)
timeformat = '{:02d}:{:02d}'.format(mins, secs)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.format was popular in python 2.x, if you want you can do the same with f string.

timeformat = f'{mins:02d}:{secs:02d}'

print(timeformat, end='\r')
time.sleep(1)
time_sec -= 1

print("stop")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"stop" can be replaced with "countdown ended".


countdown(5)