Answer:
Following are the correct code to this question:
def leap_year(year):#defining a method to check if year is leap year
if ((year%4==0) and (year%100!=0)) or (year%400==0):#defining condition to check value
return 1 #return value 1
return 0 #return 0
def number_of_days(month,year):#defining method number_of_days to calculate year or month is leap year are not
if month==2: #defining if block to calculate leap year value
if leap_year(year):#using if block to call leap_year month
return 29#return value 29
return 28 #return value 28
if month in days_31: #defining if block to calculate day
return 31 #return value 31
return 30#return value 30
def days_left(day,month,year):#defining method days_Left
daysLeft = number_of_days(month,year)-day#defining variable daysLeft which calls number_of_days method
month += 1 #increment month variable value by 1
while month<=12:#defining while loop to Calculate left days
daysLeft += number_of_days(month,year) #using daysLeft variable to hold number_of_days value
month += 1 #increment value of month variable by 1
return daysLeft #return daysLeft value
days_31 = [1,3,5,7,8,10,12] #defining days_31 dictionary and assign value
days_30 = [4,6,9,11] # defining days_30 dictionary and assign value
print('Please enter a date') #print message
day = int(input('Day: ')) #defining day variable and input value
month = int(input('Month: '))#defining Month variable and input value
year = int(input('Year: '))#defining Year variable and input value
print('Menu:')#print message
print('press 1 to Calculate the number of days in the given month.')#print message
print('press 2 to Calculate the number of days left in the given year.')#print message
choice = int(input())#defining choice variable and input the value
if choice==1: #defining if block to check choice
print(number_of_days(month,year)) #call method number_of_days and print value
elif choice==2: #defining elif block to check value
print(days_left(day,month,year))#call days_left and print value
Output:
Please enter a date
Day: 2
Month: 6
Year: 2018
Menu:
press 1 to Calculate the number of days in the given month.
press 2 to Calculate the number of days left in the given year.
2
194
Explanation:
In the given python code, three methods "leap_year, number_of_days, and days_left " is declared, in which we calculate all the values that can be described as follows:
- In the leap_year method, it accepts the year variable, which calculates the year is the leap year and returns its value that is 1.
- In the next method number_of_days, it is declared that accepts the "year and month" variable as the parameter and calculates and returns its value.
- In the last days_left method, it calculates the left days and returns its value, and outside the method, two dictionary variable days_31 and days_30 is declared, which assign a value and used use three input variable day, month, and year variable to accepts user input value.
- In the next step, a choice variable is declared, that input values and calls and print its value accordingly.