九宫格、函数入门、判断某天为某年的第几天
2018-01-28 23:57
323 查看
九宫格
# #九宫格: # 1|2|3 # 4|5|6 # 7|8|9 # 横排相加=15,竖排相加=15,两对角相加等于15 num=[] for i in range(1,10): num.append(i) #遍历x、y,当x!=y时,再遍历z,x!=z,y!=z,三个数就都不一样 L=[(x,y,z) for x in num for y in num if x!=y for z in num if x!=z and y!=z and x+y+z==15] for L1 in L: for L2 in L: if set(L1) & set(L2): #set集合,取出的第一排不能等于第二排 continue for L3 in L: if set(L1) & set(L2) & set(L3): #第一、二、三排都不等 continue elif L1[0]+L2[0]+L3[0] != 15: #竖排不等的话就跳过,横排肯定是相等的,所以不用判断 continue elif L1[1]+L2[1]+L3[1] != 15: continue elif L1[1]+L2[1]+L3[1] != 15: continue elif L1[0]+L2[1]+L3[2] != 15: #两对角不等的话就跳过 continue elif L1[2]+L2[1]+L3[0] != 15: continue else: print(''' {0}|{1}|{2} {3}|{4}|{5} {6}|{7}|{8} '''.format(L1[0],L1[1],L1[2],L2[0],L2[1],L2[2],L3[0],L3[1],L3[2]))
函数入门
判断某天为某年的第几天:
思路:比如输入:2018-03-01,需要把2月份的天数加上,在加上当前月份的天数
判断是不是闰年:可以整除4,不可以整除100,但是可以整除400
dat = input('Enter a certain year and a certain day,format: yyyy-mm-dd :') year=int(dat[0:4]) month=int(dat[5:7]) day=int(dat[8:]) Leap_year=1 #先定义不是闰年 if year % 4 == 0 and year % 100 != 0: Leap_year=0 #判断是闰年 elif year%400 == 0: Leap_year = 0 #判断是闰年 else: Leap_year = 1 if Leap_year== 0: #是闰年,2月份就是29天 ms = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] else: ms = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] days=0 if month in range(1,13): for i in range(month-1): days+=ms[i] print('{0} is this years {1} days'.format(dat,(days+day)))
相关文章推荐
- 函数入门实例、九宫格实例、判断某日是当年的第几天实例
- Python初识函数、闰年判断函数,水仙花数、学生信息管理系统、函数实现输入某年某月某日,判断这一天是这一年的第几天
- 判断某天是某年的第几天
- 输入某年某月某日,判断这一天是这一年的第几天?(哈希算法)
- 输入某年某月某日,判断这一天是这一年的第几天?
- 输入某年某月某日,判断这一天是这一年的第几天?
- 编写函数判断某年某月某日这一年中是第几天,在主函数中调用该函数。
- 输入某年某月某日,判断这一天是这一年的第几天?(闰年)思路与代码
- 输入某年某月某日,判断这一天是这一年的第几天?
- 编写函数判断某年某月某日是这一年的第几天?
- 输入某年某月某日,判断这一天是这一年的第几天?
- java经典算法_013输入某年某月某日,判断这一天是这一年的第几天?
- Problem I: 函数---判断某年某月某日是这一年中的第几天
- 输入某年某月某日,判断这一天是这一年的第几天?考虑闰年的情况
- 输入某年某月某日,判断这一天是这一年的第几天?
- 输入某年某月某日,判断这一天是这一年的第几天?
- js入门·循环与判断/利用函数的简单实例/使用对象/列举对象属性的名称
- 输入某年某月某日,判断这一天是这一年的第几天?
- 输入某年某月某日,判断这一天是这一年的第几天?
- 输入某年某月某日,判断这一天是一年的第几天 的三种方式