(Find the number of days in a month) Write a program that prompts the user to enter the month and year and displays the number of days in the month. For example, if the user entered month 2 and year 2000, the program should display that February 2000 has 29 days. If the user entered month 3 and year 2005, the program should display that March 2005 has 31 days. Sample Run 1 Enter a month in the year (e.g., 1 for Jan): 4 Enter a year: 2005 April 2005 has 30 days Sample Run 2 Enter a month in the year (e.g., 1 for Jan): 2 Enter a year: 2006 February 2006 has 28 days Sample Run 3 Enter a month in the year (e.g., 1 for Jan): 2 Enter a year: 2000 February 2000 has 29 days

Answers

Answer 1

Answer:

Follows are the code to this question:

m= int(input("Enter month: "))#defining a m variable that takes months value

y= int(input("Enter year: "))#defining a y variable that takes years value

if m in [1, 3, 5, 7, 8, 10, 12]:#use if block that check m value is in list

   n_day = 31#defining a variable n_day that holds a value  

elif m in [4, 6, 9, 11]:#use elif block that check m value is in list

   n_day = 30#defining a variable n_day that holds a value

else:#defining else block

   if y% 4 == 0 and (y % 400 == 0 or y % 100 != 0):#use if block to check leap year condition

       n_day = 29#holds value in n_day variable

   else:#defining else block

       n_day = 28#holds value in n_day variable

m_name = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October",

              "November", "December"]#defining a m_name as a list that holds string value

print(m_name[m - 1], y, "has", n_day, "days.")#print output with message.

Output:

Enter month: 6

Enter year: 2009

June 2009 has 30 days.

Explanation:

In this code two-variable "y and m" is defined that holds year and month value as an input from the user-end, and use the conditional statement to check m value, which is defined as follows:

In the first condition, if block, it checks m value is available in a given list if the condition is true it holds value "31" in n_day variable. In the second condition, elif block is used checks m value is available in another given list if the condition is true it holds value "30" in n_day variable. In the else block it check leap year condition and hold value in the "n_day variable", in the next step "m_name" variable is defined that stores string value, and uses the print method to print its calculated values.

Related Questions

Other Questions
Which substance is a product of photosynthesis? O A. Nitrogen O B. Glucose O C. Carbon dioxide O D. Water Given: D(1, 3), E(3, 1), F(3, 1), G(4, 3), and H(5, 3)Prove: triangleDEF ~ triangleDGH Which of the following methods may be used in a painting to give the illusion of three dimensional space?a.Atmospheric perspectiveb.Overlapping of formsc.Chiaroscurod.All of the above justify the property that it illustratesif the measure of angle g is 35 and the measure of angle s is 35, then the measure angle g is congruent to measure angle s. How did the split between Israel andJudah lead to the downfall of both kingdoms?HELP MEH PLS PLS ASAP PLEASE Question 12 (1 point)Profanity can limit your social and professional outcomes.TrueFalse While in Manchester, England, Jaslene bought a sweater for 28(GBP). When she returned,she saw the same sweater for $38CAD. Which sweater cost more? By how much in Canadiandollars? should there be cameras in school why or why not Someone please help me ASAP If a friend is struggling with factoring. Explain the process to factor 3xsquare-5x-12 For this PreLab assignment we will assume all of the acid is the monoprotic acid acetylsalicylic acid (C9H8O4). [Note: for your analysis in the PostLab you will subtract the moles of salicylic acid from the total acid content to determine the amount of acetylsalicylic acid]. How many moles of acetylsalicylic acid are in the 0.2001 g sample of your aspirin Four elements are shown as they appear in the periodic table 21 SC 44.956 Scandium 22 24 V Cr 47.867 50.942 51.996 Titanium Vanadium Chromium Which statement makes an accurate comparison of some of these elements? An atom of scandium contains two more protons than an atom of vanadium. B An atom of chromium contains seven more protons than an atom of scandium. An atom of titanium has fewer protons than an atom of vanadium but more protons than an atom of scandium. An atom of chromium contains four more protons than an atom of scandium but only two more prot than an atom of titanium. HELP PLEASE BENCHMARKS PLEASE 8/3 = 3 (c + 5/3) how to solve step by step Why cant we get any type of matter to absolute zero?? 1. Explain how physical geography influenced thedevelopment of civilization in ancient Greece. PLZ HELP :(The area of the green square is 9 ft. The area of the red square is 16 ft?What is the length of side c?A)5 ftB)25 ftC)81 ftD)128 ft MP1 18. Allen has 13 carrots. He wants to put an equal amount of carrots into5 sandwich sized bags. How much should Allen put into each bag?Show your work. On a coordinate plane, a line goes through points (0, 0) and (5, 8.5). A triangle is formed with the line and the y-axis.Use these similar triangles on the coordinate plane to determine the equation of a straight line with a slope of 5/3 that passes through the origin.y = five-thirds xy = three-fifths xy = 3x + 5y = 5x + 3 write 3 interesting things about plica semilunaris HELP I WILL GIVE SM POINTS Which shows the simplified expressions ordered from least to greatest by the value of the exponent?