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.
相关推荐
QxQ么么3 小时前
移远通信(桂林)26校招-助理AI算法工程师-面试纪录
人工智能·python·算法·面试
执笔论英雄4 小时前
Slime异步原理(单例设计模式)4
开发语言·python·设计模式
马克学长4 小时前
SSM青岛恒星科技学院机房管理系统0k0u9(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面
数据库·科技·ssm 框架·教育信息化·机房管理系统·青岛恒星科技学院
7***68435 小时前
Spring Boot 从 2.7.x 升级到 3.3注意事项
数据库·hive·spring boot
L***d6705 小时前
Spring Boot 各种事务操作实战(自动回滚、手动回滚、部分回滚)
java·数据库·spring boot
小徐敲java5 小时前
python使用s7协议与plc进行数据通讯(HslCommunication模拟)
开发语言·python
java_logo5 小时前
MySQL Server Docker 容器化部署指南
linux·运维·数据库·docker·容器
likuolei5 小时前
XSL-FO 软件
java·开发语言·前端·数据库
p***95005 小时前
Springboot3 Mybatis-plus 3.5.9
数据库·oracle·mybatis
猫头虎5 小时前
如何解决 pip install 编译报错 fatal error: hdf5.h: No such file or directory(h5py)问题
人工智能·python·pycharm·开源·beautifulsoup·ai编程·pip