Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help filling in the blanks. I need to write a Python program that repeatedly asks the user for a date (of the form m/d/y),

Need help filling in the blanks. I need to write a Python program that repeatedly asks the user for a date (of the form m/d/y), and then either prints that the date is invalid or prints the date in "long" format (monthName day, year). Here is a sample run of the program

#CIS 111 #Project 5 #started by Julie Thornton

#m is the month number (1-12) #returns the corresponding month name def month_num_to_name(m): #YOU DO THIS #return 'January' if m is 1, 'February' if m is 2, etc.

#Leave this here in case m is not between 1-12 return 'Invalid month'

#m is the month number (1-12) #d is the day #y is the year def get_long_format(m, d, y): #YOU DO THIS #Call month_num_to_name to convert m to its name #return the given date in long format #e.g., if m=1, d=1, y=2018, you would return 'January 1, 2018'

#Remove the line below after you finish this function return '' #y is the year #returns whether y is a leap year (True if it is, False if it's not) def is_leap_year(y): #This function is DONE! if y % 4 == 0 and (year % 100 != 0 or year % 400 == 0): return True else: return False

#m is the month number (1-12) #d is the day #y is the year def check_validity(m, d, y): #YOU DO THIS

#if m is not between 1-12, return False #if y is negative, return False

#Use if/elif statements to see which month you are in (m) #Make sure the day (d) is >= 1 and <= the number of days in that month #If it is, return True #If not, return false

#Month numbers with 31 days: 1, 3, 5, 7, 8, 10, 12 #Month numbers with 30 days: 4, 6, 9, 11 #February (m=2) usually has 28 days, but has 29 days during leap years #(Call is_leap_year to check) #Remove the line below after you are done return False

################################ #### Main code goes below: ##### ################################

#YOU DO THIS #While the user keeps saying 'y' to go again #Get a date (m/d/y) from the user #Use split to get out the month, day, and year

#Call check_validity to see if the date is valid #If it isn't, print an error #If it is valid: #Call get_long_format to get the long format of this date #Print the result from get_long_format

#Ask the user if they want to go again, and keep looping if they say yes

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions