-2

I would like to generate every single birthday possible (365 possible birthdays) in python but have no idea how to do it. I tried making a value that counts up and stops at a certain number but that won't work!

what I mean is like this: 01 01 2020 01 02 2020 01 03 2020 M D Y

Etc

Any help works!

Thanks!

  • Does this answer your question? [Creating a range of dates in Python](https://stackoverflow.com/questions/993358/creating-a-range-of-dates-in-python) – DYZ Mar 11 '20 at 01:46
  • No not really but thanks! – user12156763 Mar 11 '20 at 02:31
  • Welcome to Stack Overflow! You will get more high-quality answers if you attempt a solution and add it to your post. See https://stackoverflow.com/help/how-to-ask?utm_source=Iterable&utm_medium=email&utm_campaign=gen-welcome-email&utm_content=aug18 for advise on how to get the most useful answers from the community. – Skyler Ferris Mar 11 '20 at 02:56

2 Answers2

2

Adam gave you the solution you needed. For simplicity, you can try this:

dates = range(1, 32)
months = range(1, 13)
year = 2020

for i in months:
    for j in dates:
        print('{}/{}/{}'.format(i, j, year))

you can split 'dates' into two separate arrays of days 30 and 31 or you can apply check conditions for months not having 31 days. Hope this helps.

RAHUL MAURYA
  • 128
  • 8
1

You can try this.

dates = [1, 2, 3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]
months = [1, 2, 3,4,5,6,7,8,9,10,11,12]

for M in range(1, len(months)+1):
    for D in range(1, len(dates)+1):
        print("%d/%d/2020"%(D,M))

Output:

1/1/2020
2/1/2020
3/1/2020
4/1/2020
5/1/2020
6/1/2020
7/1/2020
8/1/2020
9/1/2020
10/1/2020
11/1/2020 ...

As your question is so broad that is why I'm writing with nested loop to achieve your requirement.

Adam Strauss
  • 1,889
  • 2
  • 15
  • 45