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 分钟前
50个Python处理Excel示例代码,覆盖95%日常使用场景-全网最全
python·excel
大模型真好玩8 分钟前
做题王者,实战拉跨!是时候给马斯克的Grok4泼盆冷水了!(Grok 4模型详细测评报告)
人工智能·python·mcp
羊八井9 分钟前
使用 Earth2Studio 和 AI 模型进行全球天气预测:太阳辐照
pytorch·python·nvidia
向左转, 向右走ˉ18 分钟前
PyTorch随机擦除:提升模型抗遮挡能力
人工智能·pytorch·python·深度学习
马特说30 分钟前
金融时间序列机器学习训练前的数据格式验证系统设计与实现
python·机器学习·金融
Blue桃之夭夭30 分钟前
基于OpenCV的实时人脸检测系统实现指南 ——Python+Haar级联分类器从环境搭建到完整部署
人工智能·python·opencv
偷偷的卷31 分钟前
【算法笔记 day three】滑动窗口(其他类型)
数据结构·笔记·python·学习·算法·leetcode
木头左33 分钟前
决策树与随机森林Python实践
python·随机森林
网小鱼的学习笔记1 小时前
python中MongoDB操作实践:查询文档、批量插入文档、更新文档、删除文档
开发语言·python·mongodb
亲爱的非洲野猪1 小时前
Oracle与MySQL详细对比
数据库·mysql·oracle