On Python
Write a program to display the name of the month according to number given by the user ( Take first 5 month).
(Don't spam)
Attachments:
![](https://hi-static.z-dn.net/files/d06/bb80415a293116c1352c93738a5f1ac2.jpg)
Answers
Answered by
6
Required Answer:-
Question:
- Write a Python program to display the name of the month according to the number given by the user. Take first five months.
Solution:
Here comes the program.
months=["January","February","March","April","May"]
n=int(input("Enter Month Number: "))
if n>=1 and n<=5:
print("Month Name: ",months[n-1])
else:
print("Sorry.")
Explanation:
Remember that the index number of list starts with 0.
From the list,
Element at index 0:- "January".
Element at index 1:- "February" and so on.
Ask the user to enter the month number (n). Subtract the month number by 1(n - 1) and display the the list element at (n - 1) location.
For example, if the input is 1, the program displays the list element at index 1 - 1 = 0 which is "January".
See the attachment for output ☑.
Attachments:
![](https://hi-static.z-dn.net/files/d22/d3e25308f8a012275e72fdc4e3625ebf.png)
![](https://hi-static.z-dn.net/files/d02/63c01809ff9cb24bf4298cd9f5b9437d.jpg)
Answered by
2
Answer:
Very Good Question
Explanation:
Similar questions
Chemistry,
3 months ago
Physics,
3 months ago
Computer Science,
6 months ago
Math,
6 months ago
Physics,
1 year ago