Free-Friday 9/19/25

Today in class, I made a countdown.

I read a tut on how to do it.

Link to tut:https://inventwithpython.com/bigbookpython/project14.html

here’s my screenshot:

import sys, time

import sevseg

secondsLeft = 30

try:

    while True:

        print(‘\n’ * 60)

        hours = str(secondsLeft // 3600)

        minutes = str((secondsLeft % 3600) // 60)

        seconds = str(secondsLeft % 60)

        hDigits = sevseg.getSevSegStr(hours, 2)

        hTopRow, hMiddleRow, hBottomRow = hDigits.splitlines()

        mDigits = sevseg.getSevSegStr(minutes, 2)

        mTopRow, mMiddleRow, mBottomRow = mDigits.splitlines()

        sDigits = sevseg.getSevSegStr(seconds, 2)

        sTopRow, sMiddleRow, sBottomRow = sDigits.splitlines()

        print(hTopRow    + ‘     ‘ + mTopRow    + ‘     ‘ + sTopRow)

        print(hMiddleRow + ‘  *  ‘ + mMiddleRow + ‘  *  ‘ + sMiddleRow)

        print(hBottomRow + ‘  *  ‘ + mBottomRow + ‘  *  ‘ + sBottomRow)

        if secondsLeft == 0:

                print()

                print(‘    * * * * BOOM * * * *’)

                break

    print()

    print(‘Press Ctrl-C to quit.’)

    time.sleep(1)

    secondsLeft -= 1

except KeyboardInterrupt:

    print(‘Countdown, by Al Sweigart al@inventwithpython.com’)

    sys.exit()

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top