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.
相关推荐
Kai HVZ40 分钟前
python爬虫----爬取视频实战
爬虫·python·音视频
古希腊掌管学习的神43 分钟前
[LeetCode-Python版]相向双指针——611. 有效三角形的个数
开发语言·python·leetcode
m0_748244831 小时前
StarRocks 排查单副本表
大数据·数据库·python
B站计算机毕业设计超人1 小时前
计算机毕业设计PySpark+Hadoop中国城市交通分析与预测 Python交通预测 Python交通可视化 客流量预测 交通大数据 机器学习 深度学习
大数据·人工智能·爬虫·python·机器学习·课程设计·数据可视化
路人甲ing..1 小时前
jupyter切换内核方法配置问题总结
chrome·python·jupyter
C++忠实粉丝1 小时前
Redis 介绍和安装
数据库·redis·缓存
游客5201 小时前
opencv中的常用的100个API
图像处理·人工智能·python·opencv·计算机视觉
wmd131643067121 小时前
将微信配置信息存到数据库并进行调用
数据库·微信
是阿建吖!1 小时前
【Linux】基础IO(磁盘文件)
linux·服务器·数据库
每天都要学信号1 小时前
Python(第一天)
开发语言·python