write a program in python that will accept a number and displaying the corresponding day of the week
Answers
Answer:
Explanation:
import calendar
def findDay(date):
day, month, year = (int(i) for i in date.split(' '))
dayNumber = calendar.weekday(year, month, day)
days =["Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday", "Sunday"]
return (days[dayNumber])
# Driver program
date = '03 02 2019'
print(findDay(date))
The following codes will have to be typed in script mode, saved and then executed.
CODE:
x = int(input("Enter a number:"))
if x == 1:
print("The first day is Sunday.")
elif x == 2:
print("The second day is Monday.")
elif x == 3:
print("The third day is Tuesday.")
elif x == 4:
print("The fourth day is Wednesday.")
elif x == 5:
print("The fifth day is Thursday.")
elif x == 6:
print("The sixth day is Friday.")
elif x == 7:
print("The seventh day is Saturday.")
else:
print("Please enter a number from 1 - 7.")
Here, we've made use of the IF - ELIF conditional statement. Once the user inputs a value, the system validates with each condition given. If it matches any one of the conditiond, the required statement will be printed.