日期转化星期,我的程序哪里不对呢
year = int(input())
m = int(input())
q = int(input())
if m == 1:
m = 13
year -= 1
elif m == 2:
m = 14
year -= 1
j = year / 100
k = year % 100
h =(q + (26 * (m + 1))/10 + k + 0.25 * (k + j) + 5 * j) % 7
if h == 0:
result = "星期六"
elif h == 1:
result = "星期天"
elif h == 2:
result = "星期一"
elif h == 3:
result = "星期二"
elif h == 4:
result = "星期三"
elif h == 5:
result = "星期四"
elif h == 6:
result = "星期五"
print(h)
print(year,"年",m,"月",q,"日是",result)
这里不应该有小数,把所有的除号换成整除号试一下 h =(q + (26 * (m + 1))/10 + k + 0.25 * (k + j) + 5 * j) % 7
#关键在这行代码,h为初次调用,h的类型看右边赋值情况
#你看(26 * (m + 1))/10,例如m=13,则计算结果是小数
#那其他代码不用看了,括号内计算结果一定是小数。小数除以7求余数也是小数
#小数用判断来比较。。。能不出问题么 import math
year = int(input("请输入年份:"))
m = int(input("请输入月份:"))
q = int(input("请输入日期:"))
if m == 1:
m = 13
year -= 1
elif m == 2:
m = 14
year -= 1
j = year / 100
k = year % 100
h = int((q + (26 * (m + 1)) % 10 + k + 0.25 * (k + j) + 5 * j) % 7)
if h == 0:
result = "星期六"
elif h == 1:
result = "星期天"
elif h == 2:
result = "星期一"
elif h == 3:
result = "星期二"
elif h == 4:
result = "星期三"
elif h == 5:
result = "星期四"
elif h == 6:
result = "星期五"
print(h)
print(year, "年", m, "月", q, "日是", result)
页:
[1]