❶ 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 获得一个月有多少天
在python的datetime模块中没有一个月有多少天的方法,但是可以使用calendar模块获得。
如下代码:
importcalendar
monthRange=calendar.monthrange(2013,6)
printmonthRange
输出:
(5,30)
输出的是一个元组,第一个元素是上一个月的最后一天为星期几(0-6),星期天为0;第二个元素是这个月的天数。
❸ Python 判断指定月份的天数
还要根据年份来的,闰年又不一样
year = int(input('请输入年份:'))
month = int(input('请输入月份(1~12):'))
if month == 2:
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
print('闰年29天')
else:
print('平年28天')
elif month in (4,6,9,11):
print('30天')
else:
print('31天')
❹ python计算不同比例的加班工资
编写工资额计算器,要求如下:
(1)确定每月的基本工资。
(2) 输入每月的实际应当工作天数。
(3) 输入当月的请假天数,如果请假天数小于等于2天,对工资无影响;大于2天小于7等于天,扣除当月基本工资的10%;大于7天小于等于14天,扣除当月基本工资的50%;大于14天,扣除全月工资。
(4) 如果当月实际工作天数和应当工作天数一样(不算加班),则增加基本工资的20%。
(5) 如果当月有加班,则按照加班的天数和当月的日工资(基本工资/实际工作天数)计算加班费。
(6) 输入最终应得工资。
❺ python编程题
mons = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
def get_days(mon, day):
if mon == 1:
return mons[0], day
else:
count = sum(mons[:mon-1])
count = count + day
return mons[mon - 1], count
mon = int(input("请输入月份:"))
day = int(input("请输入号数:"))
result = get_days(mon, day)
print("{}月有{}天。".format(mon, result[0]))
print("{}月{}号是该年的第{}天".format(mon, day, result[1]))
❻ 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 创建一个列表,依次存放每个月对应的天数,假设2月份的天数为28天,根据用户输入的月份
l = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
while True:
a = eval(input('请输入月份(输入0退出):'))
if a == 0:
exit()
try:
print('{}月共有{}天'.format(a, l[a-1]))
except:
print('你的输入有误!')
❽ Python datetime 怎么拿出每个月的总天数
>>> import calendar
>>> now_year=2012
>>> now_month=7
>>> calendar.monthrange(now_year,now_month)
(6, 31)
>>> calendar.monthrange(now_year,now_month)[1]
31
❾ Python:要求用 函数 实现: 从键盘输入年份和月份,然后计算返回该年该月共有多少天。
#encoding:utf-8
#Python3.6.0
defgetdays():
year=input("输入年份:")
month=input("输入月份:")
ifyear==""ormonth==""oryear.isdigit()==Falseormonth.isdigit()==False:
return"输入非法"
m=[31,28,31,30,31,30,31,31,30,31,30,31]
ifint(year)%4==0andint(year)%100!=0orint(year)%400==0:
m[1]=29
return"{0}年{1}月有{2}天".format(year,month,m[int(month)-1])
print(getdays())
❿ 求Python 代码 从键盘输入年份和月份,在屏幕上输出该月的天数(要考虑闰年)
楼上的写的没什么问题,可是你的算法中有一个失误,那就是年份为100的倍数时,要能够整除400才能是29天,所以“”“case2:day=year%4==0?29:28;”“”这一句要改为"""case2:day=year%100==0?year%400==0?29:28:year%4==0?29:28;""