发布时间:2019-09-25 08:16:40编辑:auto阅读(1696)
5.1 九宫格
5.2 函数入门
5.3 判断某天为某年的第几天
import random
x = 0
l = [1,2,3,4,5,6,7,8,9]
print("*************")
while len(l) != 0:
n = int(random.random() * 100 % len(l))
#print(x)
#print(n)
d = l.pop(n)
print("|_{0}_".format(d),end="")
x += 1
if x == 3:
print("|")
x = 0
print("*************")
# 函数
def a(args):
pass
##################
def add(args):
total = 0
for i in args:
total += i
return total
def main():
number = list()
s = input("请输入(a + b + c + d + ...):")
for num in s.split("+"):
number.append(int(num.strip()))
print(add(number))
if __name__ == '__main__':
main()
a = {"1":31, "2":28, "3":31, "4":30, "5":31, "6":30, "7":31, "8":31,
"9":30, "10":31, "11":30, "12":31}
b = {"1":31, "2":29, "3":31, "4":30, "5":31, "6":30, "7":31, "8":31,
"9":30, "10":31, "11":30, "12":31}
days = 0
date = input("输入日期(1970-1-1):")
year, month, day = date.split("-")
if int(day) > 31:
print("输入错误!")
elif int(month) > 12:
print("输入错误!")
elif ((int(year) % 4 == 0) and (int(year) % 100 != 0)) or ((int(year) % 100 == 0) and (int(year) % 400 == 0)):
if b[month] < int(day):
print("输入错误!")
else:
for k, y in b.items():
if int(k) < int(month):
days += int(y)
print("{0}是今年的第{1}天!".format(date, days + int(day)))
else:
if a[month] < int(day):
print("输入错误!")
else:
for k, y in a.items():
if int(k) < int(month):
days += int(y)
print("{0}是今年的第{1}天!".format(date, days + int(day)))
上一篇: python3 面向对象的创建及实例的属
下一篇: python3第二天(基本数据类型)
47768
46278
37155
34658
29248
25909
24781
19883
19444
17939
5734°
6339°
5856°
5905°
7009°
5844°
5865°
6375°
6335°
7701°