Respuesta :
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.
The calendar program illustrates the use of conditional statements
In programming, conditional statements are used to make decisions.
The calendar program in Python where comments are used to explain each line is as follows:
#This defines the function that calculates the days in a month
def daysMonth(month,year):
#This checks for leap year (i.e. February), and returns the number of days
if month==2:
if ((year%4==0) and (year%100!=0)) or (year%400==0):
return 29
return 28
#This checks and returns the number of days in the other months
if month in [1,3,5,7,8,10,12]:
return 31
return 30
#This defines the function that calculates the days remaining in a year
def countDays(day,month,year):
#This calculates the days remaining in the current month
daysLeft = daysMonth(month,year)-day
month += 1
#The following loop determines the days left in the year
while month<=12:
daysLeft += daysMonth(month,year)
month += 1
#The returns the days left in the year
return daysLeft
#This gets the day as input
day = int(input('Day: '))
#This gets the month as input
month = int(input('Month: '))
#This gets the year as input
year = int(input('Year: '))
#This gets the choice
choice = int(input("1 - Days in the month\n2 - Days left in the year\nChoice: "))
#If the choice is 1, this prints the days in the month
if choice==1:
print("There are",daysMonth(month,year),"days in the month")
#If the choice is 2, this prints the days left in the year
elif choice==2:
print("There are",countDays(day,month,year),"left in the year")
Read more about conditional statements at:
https://brainly.com/question/19248794