Python Project Calendar Maker

Overview

This program generates printable text files of monthly calendars for the month and year your enter. Dates and calendars are a tricky topic in programming because there are so many different rules for determining the number of days in a month, which years are leap years, and whcih day of the week a particular date falls on. Fortunately , Python's datetime moudle handles these details for you. This program focuses on generating the multiline string for the monthly calendarr page.

The Program in Action

How It Works

python 复制代码
""" Countdown , by Maxwell Pan 
Show a countdown timer animation using a seven-segment display.
Press Ctrl-C to stop.
More info at https://en.wikipedia.org/wiki/Seven-segment_display
Requires sevseg.py to be in the same folder.
View this code at https://nostarch.com/big-book-small-python-projects
Tags: tiny, artistic"""

import sys, time
import sevseg # Import our sevseg.py program.

# (!) Change this to any number of seconds:
secondsLeft = 1500

try:
    while True: #Main program loop.
        # Clear the screen by printing several newlines:
        print('\n' * 60)


        # Get the hours/minutes/seconds from secondsleft:
        # For example: 7265 is 2 hours, 1 minutes, 5 seconds.
        # So 7265 // 3600 is 2 hours:
        hours = str(secondsLeft // 3600)
        # And 7265 % 3600 is 65 , and 65 // 60 is 1 minute:
        minutes = str((secondsLeft % 3600) // 60)
        # And 7265 % 60 is 5 seconds:
        seconds = str(secondsLeft % 60)

        # Get the digit strings from the sevseg module:
        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()

        # Display the digits:
        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) # Insert a one-second pause.
        secondsLeft -= 1
except KeyboardInterrupt:
    print('Countdown, by Maxwell')
    sys.exit() # When Ctrl-C is pressed, end the program.
相关推荐
迷路剑客2 分钟前
ES-7.10-高亮HighLight知识点总结
java·数据库·mybatis
西红市杰出青年3 分钟前
asyncio.gather 内部原理与运行机制(详解)
网络·python·异步
70asunflower4 分钟前
torch.manual_seed()介绍
人工智能·pytorch·python
程序边界6 分钟前
解锁时序数据新玩法:金仓数据库实战体验分享
数据库
西红市杰出青年12 分钟前
Playwright 的 BrowserContext 与 Page:原理与实践指南
python
Tianwen_Burning16 分钟前
pycharm下配置halcon
python
汉堡go18 分钟前
python_chapter6
前端·数据库·python
范纹杉想快点毕业18 分钟前
嵌入式工程师一年制深度进阶学习计划(纯技术深耕版)
linux·运维·服务器·c语言·数据库·算法
storyseek24 分钟前
关于Milvus向量数据库的基础
数据库·milvus
摘星编程25 分钟前
React Native鸿蒙:Geolocation持续定位更新
python