(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

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 9SA
icon
Related questions
Question

Please use Python to complete this

(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
Transcribed Image Text:(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
Expert Solution
Code

Code:-

print("1 for January")
print("2 for February")
print("3 for March")
print("4 for April")
print("5 for May")
print("6 for June")
print("7 for July")
print("8 for August")
print("9 for September")
print("10 for October")
print("11 for November")
print("12 for December")
month = int(input("Enter the month in the year:- "))
year = int(input("Enter a year:- "))
if(month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12):
    print("Number of days is 31")
elif((month == 2) and ((year%400==0) or (year%4==0 and year%100!=0))):  
    print("Number of days is 29")
elif(month == 2):
    print("Number of days is 28")
else:
    print("Number of days is 30")
 
 
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 4 images

Blurred answer
Knowledge Booster
Basics of loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning