Welcome to Westonci.ca, your ultimate destination for finding answers to a wide range of questions from experts. Our platform provides a seamless experience for finding reliable answers from a knowledgeable network of professionals. Connect with a community of professionals ready to help you find accurate solutions to your questions quickly and efficiently.

Python exercise grade 10

Write a program that determines which dates comes earlier on the calendar. The user

may enter any number of dates. The user will enter 0/0/0 to indicate that no more dates

will be entered

Example:
Enter a date (month): 3

Enter a date (date): 6

Enter a date (year): 2008

03/06/2008

Enter a date (month): 5

Enter a date (date): 17

Enter a date (year): 2007

05/17/2007

Enter a date (month): 6

Enter a date (date): 3

Enter a date (year): 2007

06/03/2007

Enter a date (month): 0

Enter a date (date): 0

Enter a date (year): 0

5/17/2007 is the earliest date


Sagot :

earliest = ""

while True:

   month = int(input("Enter a date (month): "))

   day = int(input("Enter a date (date): "))

   year = int(input("Enter a date (year): "))

   if month == 0 and day == 0 and year == 0:

       break

   if month < 10:

       month = "0"+str(month)

   if day < 10:

       day = "0"+str(day)

   string_date = str(month)+"/"+str(day)+"/"+str(year)

   print(string_date)

   if earliest == "":

       earliest = string_date

   else:

       year,month,day=int(year),int(month),int(day)

       lst = list(map(int,earliest.split("/")))

       if year < lst[2]:

           earliest = string_date

       elif year == lst[2] and month < lst[0]:

           earliest = string_date

       elif year == lst[2] and lst[0] == month and day < lst[1]:

           earliest = string_date

print(earliest,"is the earliest date")

I wrote my code in python 3.8. Best of luck.

Visit us again for up-to-date and reliable answers. We're always ready to assist you with your informational needs. Your visit means a lot to us. Don't hesitate to return for more reliable answers to any questions you may have. Thank you for choosing Westonci.ca as your information source. We look forward to your next visit.