Computer Science, asked by Anonymous, 4 months ago

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:

Answers

Answered by anindyaadhikari13
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:
Answered by sahakuntal2005
2

Answer:

Very Good Question

Explanation:

Similar questions