源码:
def Day(year,month):
if month > 12 or month <= 0:
print("输入错误!")
return False
elif month == 2:
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
day = 28
print("%d月有%d天" % (month, day))
day = 29
print("%d月有%d天" % (month, day))
elif month in (4,6,9,11):
day = 30
print("%d月有%d天" % (month, day))
else:
day = 31
print("%d月有%d天" % (month, day))
n = int(input("您想查阅几次月份天数:"))
while n > 0:
year = int(input("请输入年份:"))
month = int(input("请输入月份(1-12) :"))
Day(year, month)
n -= 1
源码:
def Stick(hour,minute,second):
if hour < 0 and hour > 24:
print("输入形式错误!")
elif minute < 0 and minute > 60:
print("输入形式错误!")
elif second < 0 and second > 60:
print("输入形式错误!")
else:
print("时间为%d 小时 %d 分钟 %d 秒:"%(hour,minute,second+1))
hour = int(input("小时为:"))
minute = int(input("分钟为:"))
second = int(input("分钟为:"))
Stick(hour,minute,second)
源码:
def Bubble(List):
n = len(List)
for i in range(n - 1):
for j in range(n - i - 1):
if List[j] > List[j + 1]:
List[j], List[j + 1] = List[j + 1], List[j]
print("排序后:", List)
List = list(input("请输入一串数字:"))
print("排序前:",List)
Bubble(List)