2021年1月6日星期三

Create a list by looping over numbers in different dict

I'm trying to create a list by looping over days and months in year 2020 and if month + day + year = 7 then I need to add that to the list. However if the month is 11 then the program should do 1 + 1 = 2 (and not 11) so instead of using lists I have done a dict with values. But I'm not if I'm missing something.

Here is my code so far:

day = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, 10:1, 11:2, 12:3, 13:4, 14:5, 15:6, 16:7, 17:8, 18:9, 19:10, 20:2, 21:3, 22:4, 23:5, 24:6, 25:7, 26:8, 27:9, 28:10, 29:11, 30:3, 31:4}  month = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, 10:1, 11:2, 12:3,}  year = {20:2}  dagar_007 = []    def ordning(m,d,y):          for y in year.values():          for m in month.values():              if m == 2:                  for d in day.values():                      if y + m + d == 7:                          if d == 30:                              break                          dagar_007.append(ordning)              elif m == 4 or 6 or 8 or 11:                  for d in day.values():                      if y + m + d == 7:                          if d == 31:                              break                          dagar_007.append(ordning)              else:                                                                 for d in day.values():                      if y + m + d == 7:                          dagar_007.append(ordning)                          if d == 32:                              break  print(dagar_007)    # How it kind of looks like    print("List of days with sum 7:")  # 1/4/20 007    print(dagar_007, "007")    print(datetime.datetime.strftime(x,"%m/%d/%y"))    print("Sannolikheten: ", len(dagar_007) / 366 * 100, "%")  print("in other words:", len(dagar_007), "chances on 366")  
https://stackoverflow.com/questions/65592836/create-a-list-by-looping-over-numbers-in-different-dict January 06, 2021 at 04:57PM

没有评论:

发表评论