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.
相关推荐
CANI_PLUS11 分钟前
ESP32将DHT11温湿度传感器采集的数据上传到XAMPP的MySQL数据库
android·数据库·mysql
qq_3325394512 分钟前
Python自动化测试实战:reCAPTCHA V3绕过技术深度解析
自动化测试·python·web安全·验证码破解·recaptcha
大模型真好玩1 小时前
深入浅出LangChain AI Agent智能体开发教程(八)—LangChain接入MCP实现流程
人工智能·python·mcp
阿松のblog2 小时前
vue3+ts+flask+websocket实现实时异物检测
python·websocket·flask
国王不在家3 小时前
3.5-非关系型数据库-反规范化-sql语言
数据库·nosql
Code季风5 小时前
如果缓存和数据库更新失败,如何实现最终一致性?
数据库·分布式·缓存·微服务·性能优化
TS的美梦5 小时前
scanpy单细胞转录组python教程(四):单样本数据分析之降维聚类及细胞注释
python·数据分析·聚类·单细胞转录组·scanpy
Runing_WoNiu5 小时前
mysql 索引失效分析
数据库·mysql
一涯5 小时前
用python写一个抓取股市关键词的程序
前端·python
老纪的技术唠嗑局6 小时前
Dify + OceanBase,AI 业务多场景落地实践
数据库·人工智能