① 新手求助,如何用python写日历让三个月在在
直接使用pythoncalender模块即可。
calendar.calendar(year,w=2,l=1,c=6)
返回一个多行字符串格式的year年年历,3个月一行,间隔距离为c。每日宽度间隔为w字符。每行长度为21*W+18+2*C。l是每星期行数。
2. calendar.firstweekday()
返回当前每周起始日期的设置。默认情况下,首次载入caendar模块时返回0,即星期一。
3. calendar.isleap(year)
是闰年返回True,否则为false。
4. calendar.leapdays(y1,y2)
返回在Y1,Y2两年之间的闰年总数。
5. calendar.month(year,month,w=2,l=1)
返回一个多行字符串格式的year年month月日历,两行标题,一周一行。每日宽度间隔为w字符。每行的长度为7*w+6。l是每星期的行数。
6. calendar.monthcalendar(year,month)
返回一个整数的单层嵌套列表。每个子列表装载代表一个星期的整数。Year年month月外的日期都设为0;范围内的日子都由该月第几日表示,从1开始。
7. calendar.monthrange(year,month)
返回两个整数。第一个是该月的星期几的日期码,第二个是该月的日期码。日从0(星期一)到6(星期日);月从1到12。
8. calendar.prcal(year,w=2,l=1,c=6)
相当于printcalendar.calendar(year,w,l,c).
9. calendar.prmonth(year,month,w=2,l=1)
相当于printcalendar.calendar(year,w,l,c)。
10. calendar.setfirstweekday(weekday)
设置每周的起始日期码。0(星期一)到6(星期日)。
11. calendar.timegm(tupletime)
和time.gmtime相反:接受一个时间元组形式,返回该时刻的时间辍(1970纪元后经过的浮点秒数)。
12. calendar.weekday(year,month,day)
返回给定日期的日期码。0(星期一)到6(星期日)。月份为1(一月)到12(12月)。
② 在python中用if编写输入一个月份并计算有多少天
a=eval(input('请输入月份:'))
whilenot(isinstance(a,int)and0<a<13):
a=eval(input('请输入正确的月份:'))
da=[1,3,5,7,10,12]
xiao=[4,6,8,9,11]
if(ainda):
print(a,'月有31天')
elif(ainxiao):
print(a,'月有30天')
else:
n=eval(input('请输入月所在年:'))
ifn%400==0or(n%4==0andn%100!=0):
print(n,'年为闰年',a,'月有29天')
else:
print(n,'年为平年',a,'月有28天')
③ python 练习 输入年月 输出当年当月日历 求代码 重赏
如果要做成桌面应用的话,你还需要安装eric4
就有点类似vc++,可以选择控件并添加代码
④ 急求大神教如何在Python里编写日历让三个月在同一排输出
在你输入月份之前加上这句(注意语句缩进):
forminrange(1,13):
#这里是你的print,注意:要修改下,print月份后面加上一个逗号,(加上逗号就不会print回车了)
#.......
#最后加上这句:
ifm%3==0:
print' '#输完三个月份后才回车
⑤ python输入月份判断天数怎么操作
编写一个函数day_of_month(year,month)
编写程序输入年(year)、月(month),调用该函数,返回该年份该月的天数,输出返回的天数。
公历闰年的计算方法为:
年份能被4整除且不能被100整除的为闰年
或者,年份能被400整除的是闰年。
ifmonth==2:
ifyear%4==0andyear%100!=0oryear%400==0:
print('闰年29天')
else:
print('平年28天')
elifmonthin(4,6,9,11):
发展历史:
由于Python语言的简洁性、易读性以及可扩展性,在国外用Python做科学计算的研究机构日益增多,一些知名大学已经采用Python来教授程序设计课程。例如卡耐基梅隆大学的编程基础、麻省理工学院的计算机科学及编程导论就使用Python语言讲授。
⑥ python输入一个年份,若是闰年,则输出该年二月的月历,若非闰年,则输出该年所有
||#include<stdio.h>
void Judge(int y)
{
while(1)
{
printf("请输入要计算的年份:\n");
scanf("%d",&y);
if((y%100==0)&&(y%400==0)||(y%100!=0)&&(y%4==0))
printf("%d年是闰年,该年2月份有29天\n",y);
else
printf("%d年是平年,该年2月份有28天\n",y);
printf("\n");
}
}
void main()
{
int year;
Judge(year);
}
⑦ 想用python做个输入年、月,显示当年当月日历的小程序,本人菜鸟,请教各位前辈。重重有赏
import datetime
import calendar
def getYM():
''' 这是一个简单的年月输入方法 '''
year = raw_input('Input Year: ')
month = raw_input('Input Month: ')
return year, month
def saveGetYM():
''' 这是一个安全的年月输入方法 '''
while True:
try:
year_month = raw_input('Input year and month (year,mont): ')
year, month = year_month.split(',')
year, month = int(year), int(month)
if 1900<=year<=2200 and 1<=month<=12:
break
except:
continue
return year, month
year,month = saveGetYM()
c = calendar.Calendar(1)
print '-- %d --'%year
for w in c.monthdatescalendar(year,month)[:7:]:
print '|'.join([d.strftime('%m-%d') for d in w])
⑧ python任意输入一个月份(1—12),判断该月份有多少天(不考虑2月份29天的特殊情况)
def month(n):
if n in [1,3,5,7,8,10,12]:
return 31
elif n in [4,6,9,11]:
return 30
elif n in [2]:
return 28
else:
return n, " is not a month"
⑨ python显示农历日期
需安装sxtwl包,命令如下
pip install sxtwl
农历(Lunar calendar)<->阳历(solar calendar)转换
代码如下(基于python3):
import sxtwl
#日历中文索引
ymc = [u"十一", u"十二", u"正", u"二", u"三", u"四", u"五", u"六", u"七", u"八", u"九", u"十" ]
rmc = [u"初一", u"初二", u"初三", u"初四", u"初五", u"初六", u"初七", u"初八", u"初九", u"初十", \
u"十一", u"十二", u"十三", u"十四", u"十五", u"十六", u"十七", u"十八", u"十九", \
u"二十", u"廿一", u"廿二", u"廿三", u"廿四", u"廿五", u"廿六", u"廿七", u"廿八", u"廿九", u"三十", u"卅一"]
# 日历库实例化
lunar = sxtwl.Lunar()
# 1.阴历转阳历
solar_day = lunar.getDayByLunar(2019,7,27)
print("公历(阳历):{0}年{1}月{2}日".format(solar_day.y, solar_day.m, solar_day.d))
# 2.阳历转阴历
from datetime import date
today = str(date.today()) # 如 2019-08-08
today_list = today.split('-') # ['2019', '08', '08']
lunar_day = lunar.getDayBySolar((int)(today_list[0]),(int)(today_list[1]),(int)(today_list[2])) # 输入年月日
# 判断是否为润年
if(lunar_day.Lleap):
print("阴历(农历):{0}月{1}".format(ymc[lunar_day.Lmc], rmc[lunar_day.Ldi]))
else:
print("阴历(农历):{0}月{1}".format(ymc[lunar_day.Lmc], rmc[lunar_day.Ldi]))
结果为
'''
公历(阳历):2019年8月27日
阴历(农历):七月初八
'''