1 #######################Day1#################### 2 #################part1########################## 3 ''' 4 四舍五入法:直接使用int函数取整数即可 5 ''' 6 def get_math(str1): 7 # str1 = '100756' 8 res = int(int(str1)/3)-2 9 return res 10 li = [] 11 path = r'E:\厦门银行数据\santa\text.txt' 12 with open(path,'r',encoding='utf-8') as f: 13 text = f.readlines() 14 for i in text: 15 x = get_math(i.strip()) 16 li.append(x) 17 print(sum(li)) 18 #####################part2####################### 19 ''' 20 循环使用四舍五入法 21 加入判断,到小于0的时候停止 22 全部求和 23 ''' 24 str1 = '100756' 25 def get_math_2(str1): 26 li = [] 27 res = 1 28 while res>0: 29 res = int(int(str1)/3)-2 30 str1 = res 31 if res > 0: 32 li.append(res) 33 return sum(li) 34 li = [] 35 path = r'E:\厦门银行数据\santa\text.txt' 36 with open(path,'r',encoding='utf-8') as f: 37 text = f.readlines() 38 for i in text: 39 x = get_math_2(i.strip()) 40 li.append(x) 41 print(sum(li))
advent of code in 2019
猜你喜欢
转载自www.cnblogs.com/pandaboy1123/p/11968828.html
今日推荐
周排行