万年历的部分功能
来源:互联网 发布:mmd r18动作数据 编辑:程序博客网 时间:2024/06/04 18:36
python源代码:
#Print the calendar for a month in a yeardef printMonth(year, month): printMonthTitle(year, month) printMonthBody(year, month)#Print the month title, eg: May 1999def printMonthTitle(year, month): print ' ', getMonthName(month), ' ', year print '-----------------------------------' print ' Sun Mon Tue Wed Thu Fri Sat'#Print month bodydef printMonthBody(year, month): startDay = getStartDay(year, month) numberOfDaysInMonth = getNumberOfDaysInMonth(year, month) i = 0 for i in range(startDay): #Pad space before the first day of the month print ' ', for i in range(1, numberOfDaysInMonth + 1): print format(i, "4d"), if (i + startDay) % 7 == 0: #jump to the new line print ''#Get the English name for the monthdef getMonthName(month): if month == 1: monthName = "January" elif month == 2: monthName = "February" elif month == 3: monthName = "March" elif month == 4: monthName = "April" elif month == 5: monthName = "May" elif month == 6: monthName = "June" elif month == 7: monthName = "July" elif month == 8: monthName = "August" elif month == 9: monthName = "September" elif month == 10: monthName = "October" elif month == 11: monthName = "November" else: monthName = "December" return monthNamedef getStartDay(year, month): START_DAY_FOR_JAN_1_1800 = 3 totalNumberOfDays = getTotalNumberOfDays(year, month) return (totalNumberOfDays + START_DAY_FOR_JAN_1_1800) % 7#Get total number days since January 1, 1800def getTotalNumberOfDays(year, month): total = 0 for i in range(1800, year): if isLeapYear(i): total = total + 366 else: total = total + 365 for i in range(1, month): total = total + getNumberOfDaysInMonth(year, i) return total#Get the number of days in a monthdef getNumberOfDaysInMonth(year, month): if(month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month== 10 or month == 12): return 31 if month == 4 or month == 6 or month == 9 or month == 11: return 30 if month == 2: if isLeapYear(year): return 29 else: return 28 return 0#Determine if it is a leap yeardef isLeapYear(year): return year%400==0 or (year%4==0 and year%100!=0)def main(): #Prompt the user to enter the year and month year = eval(raw_input("Enter year(example, 2001): ")) month = eval(raw_input("Enter month(1~12): ")) #Print calendar for the month of the year printMonth(year, month)#call the main functionmain()
0 0
- 万年历的部分功能
- 自制的万年历收音机功能完工。
- 模仿万年历,制作的考勤功能
- 万年历软件各个接口功能的实现
- c语言部分万年历
- JS日历,(万年历)功能和界面都挺好的
- 基于至简设计法实现的万年历功能
- 一个不错的万年历
- 万年历的公式
- 万年历的源代码
- 万年历的编写
- 精美的HTML万年历
- JS的初级阶段,万年历
- JS的初级阶段,万年历
- 控制台下的万年历
- Excel万年历的制作
- 老师写的万年历
- java编写的万年历
- 面试前应该了解公司的哪些信息?
- git设置代理
- CRON表达式
- Java生成和操作Excel文件(读、写)
- main:处理命令行选项 知识点总结
- 万年历的部分功能
- spark基于用户的协同过滤算法与坑点,提交job
- java基于反射的Map转Bean的工具类
- rails 练习2 --完成CRUD功能
- 35.JavaScript的对象的创建和继承
- RealVNC - No matching security types
- centos安装lnmp
- XSS 跨站脚本攻击
- cocos2dx[3.2](9) ——数学类Vec2/Size/Rect