Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(3 points) Write a program that receives 3 integer inputs, which represent a mon

ID: 3563470 • Letter: #

Question

(3 points) Write a program that receives 3 integer inputs, which represent a month, a date, and a year (for example, input of 9 23 2013 represents September 23, 2013). The user should type the inputs all on one line. The program outputs whether or not the input represents a valid date. Keep in mind that April, June, September, and November have 30 days, February has either 28 or 29 days (depending on whether it is a leap year), and the other months have 31 days. Leap years are years that are divisible by 4 or 400, but not divisible by 100 (so 2016 and 2020 are leap years, 2100 and 2200 are not, but 2400 is).

Some examples:>>> Enter a month, date, and year: 1 5 2014 Valid date>>> ================================ RESTART ================================>>> Enter a month, date, and year: 1 31 2014 Valid date>>> ================================ RESTART ================================>>>>>> ================================ RESTART ================================ Enter a month, date, and year: 1 32 2014 Invalid date>>> ================================ RESTART ================================>>> Enter a month, date, and year: 4 31 2014 Invalid date>>> ================================ RESTART ================================>>> Enter a month, date, and year: 2 28 2014 Valid date>>> ================================ RESTART ================================>>> Enter a month, date, and year: 2 29 2014 Invalid date>>> ================================ RESTART ================================>>> Enter a month, date, and year: 2 29 2012 Valid date>>> ================================ RESTART ================================>>> Enter a month, date, and year: 2 29 2000 Valid date>>> Enter a month, date, and year: 2 29 2100 Invalid date

Divisible by 4 Leap year End of a century Not leap year with the exception of years that end a century (since there was no year 0, these are years such as 2000, 2100, etc).

Some examples:>>> Enter a month, date, and year: 1 5 2014 Valid date>>> ================================ RESTART ================================>>> Enter a month, date, and year: 1 31 2014 Valid date>>> ================================ RESTART ================================>>>>>> ================================ RESTART ================================ Enter a month, date, and year: 1 32 2014 Invalid date>>> ================================ RESTART ================================>>> Enter a month, date, and year: 4 31 2014 Invalid date>>> ================================ RESTART ================================>>> Enter a month, date, and year: 2 28 2014 Valid date>>> ================================ RESTART ================================>>> Enter a month, date, and year: 2 29 2014 Invalid date>>> ================================ RESTART ================================>>> Enter a month, date, and year: 2 29 2012 Valid date>>> ================================ RESTART ================================>>> Enter a month, date, and year: 2 29 2000 Valid date>>> Enter a month, date, and year: 2 29 2100 Invalid date

Explanation / Answer

1. import calendar

inp = raw_input("Enter a month, date and year")
items = inp.split(" ")
if(len(items) != 3):
print "Invalid date"
else:
month = int(items[0])
date = int(items[1])
year = int(items[2])
if(month <= 12 and date<=31):
if(date<=28):
print "Valid date"
else:
if(date==29):
if(month != 2 ):
print "Valid date"
else:
if(calendar.isleap(year)):
print "Valid date"
else:
print "Invalid date"
if(date==30):
if(month != 2):
print "Valid date"
else:
print "Invalid date"
if(date==31):
if(month<=7):
if(month == 2):
print "Invalid date"
if(month%2 == 0):
print "Invalid date"
else:
print "Valid date"
else:
if(month%2 == 0):
print "Valid date"
else:
print "Invalid date"
else:
print "Invalid date"

2.

str = raw_input("Grade: ")
num = 0
if(len(str) <= 2):
if(str[0] == 'A'):
num = 4
if(str[0] == 'B'):
num = 3
if(str[0] == 'C'):
num = 2
if(str[0] == 'D'):
num = 1
if(str[0] == 'F'):
num = 0

if(len(str) == 2):
if(str[1] == '+'):
num = num+0.3
elif(str[1] == '-'):
num = num-0.3
print num
else:
print "Invalid input"

3.

time = raw_input("Day hour and session: ")
item = time.split(" ")

if(len(item) == 3):
day = item[0]
hour = item[1]
sess = item[2]

if(day == 'Mo' or day == 'Tu' or day == 'We' or day == 'Th' or day == 'Fr'):
if(sess == 'AM' or sess == 'am'):
if(9 <= int(hour) <= 11):
print "Is during business hours"
else:
print "Not during business hours"
elif(sess == 'PM' or sess=='pm'):
if((1 <= int(hour) <= 5) or int(hour) == 12):
print "Is during business hours"
else:
print "Not during business hours"
else:
print "Not during business hours"