38.7k views
2 votes
Please help with this code!

Please help with this code!-example-1
User Benrg
by
5.6k points

1 Answer

1 vote

import random

months = ["jan", "feb", "mar", "apr", "may", "june", "july", "aug", "sept", "oct", "nov", "dec"]

pick1 = random.choice(months)

pick2 = random.choice(months)

if months.index(pick1) < months.index(pick2):

print(pick1)

print(pick2)

else:

print(pick2)

print(pick1)

Since the months are already in chronological order in the list, we can compare their index and print the string with the smaller index first. I wrote my code in python 3.8. I hope this helps.

User Alex Anderson
by
5.8k points