python实验报告代写

编程入门 行业动态 更新时间:2024-10-26 09:29:42

python实验报告<a href=https://www.elefans.com/category/jswz/34/1743341.html style=代写"/>

python实验报告代写

代写python实验、代写python计算日期实验作业

日期:2018-05-07 10:07

实验:2.计算日期

实验内容:计算给定日期的星期

实验目的:掌握python中if语句的使用

掌握字符串的切片的方法

掌握时间合理性的判断

In this program you will prompt the user to enter the day, month, and year. Your program will print out the day of the week for that date. Here is a sample output for the program: (此程序中,输入日期,时间和年份,程序输出此日期的星期,其格式如下:)

Enter year: 1960

Enter month: 12

Enter day: 12

The day is Monday.

Assume that all the input values will be positive integers. The day will be in the range 1 through 31. The month will be in the range 1 through 12 where 1 is for January and 12 is for December. The year will be a four digit number in the range 1900 through 2100. (假设输入的值都为正整数,日期在1到31之间,月份在1到12之间,1代表1月,12代表12月,输入的年份为四位数字在1900到2100之间。)

Your program will check the following: (程序检测如下条件:)

?The year is between 1900 and 2100. (年份在1900到2100)

?The month is in the range 1 and 12. (月份在1到12)

?The day is in the range appropriate for that month. For months other than February, the range of days will be from 1 to 30 or 31 days. The range of days for February is between 1 and 28 or 29 depending on whether the year is a leap year or not. (日期是这个月份的合理日期,除了二月份,值在1到30或者31,二月份的值由是否闰年决定为28或者29)

程序先判断输入的各个值是否合理,如果不合理,提示错误并退出程序,退出程序用exit()函数

This algorithm was developed by Rev. Zeller. Let us define the quantities a, b, c, and d as follows:(程序的算法如下:)

?a ≡ the month of the year, with March = 1, April = 2, … with January = 11, and February = 12 of the preceding year

?b ≡ the day of the month(日期)

?c ≡ the year of the century(年)

?d ≡ the century, though not in the conventional sense. For example, after making adjustments for the months of January and February, for all years like 1910, 1949, 1984, the value of d = 19. And for years like 2003, 2010, 2025, the value of d = 20. (年份的前两个值)

Important: In our calendar, the year begins in January and ends in December. In the calendar, used in the algorithm, the year begins in March and ends in February. Your program should internally make the adjustment and not expect the user to know this. For example, if in our calendar we have January 2009 (month = 1 and year = 2009), the program will make the adjustment so that month = 11 and year = 2008. If you do not make the adjustment you will not get the right result. (提示:在日历中,开始为1月,结束为12月,而程序中,开始为三月,结束为二月,所以程序要对用户输入的月份和年份进行调整,而不期望用户知道这些知识。如2009.1调整完为2008.11)

例如:

For example, 31 July 1929, gives a = 5, b = 31, c = 29, and d = 19. Similarly, 3 January 1988, gives a = 11, b = 3, c = 87, and d = 19

下面为具体算法:.

Now compute the following quantities:

?w = (13 * a - 1 ) // 5

?x = c // 4

?y = d // 4

?z = w + x + y + b + c - 2 * d

?r = z % 7

?r = (r + 7) % 7 [to take care of negative values of r]

r gives the day of the week. r = 0 represents Sunday, r = 1 represents Monday, and so on. The output from your file should match the following statement: (r给出具体的星期,如果是0代表星期日,1代表星期1,以此类推)

The day is Monday.

Where Monday may be replaced by any day of the week.

更多推荐

python实验报告代写

本文发布于:2024-02-08 21:55:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1675493.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代写   报告   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!