CBSE Class 12 Computer Science
Question 99 of 105
Python Revision Tour — Question 5
Back to all questions 5
Question Write a program that asks the user the day number in a year in the range 2 to 365 and asks the first day of the year — Sunday or Monday or Tuesday etc. Then the program should display the day on the day-number that has been input.
dayNames = ["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"]
dayNum = int(input("Enter day number: "))
firstDay = input("First day of year: ")
if dayNum < 2 or dayNum > 365:
print("Invalid Input")
else:
startDayIdx = dayNames.index(str.upper(firstDay))
currDayIdx = dayNum % 7 + startDayIdx - 1
if currDayIdx >= 7:
currDayIdx = currDayIdx - 7
print("Day on day number", dayNum, ":", dayNames[currDayIdx])Enter day number: 243
First day of year: FRIDAY
Day on day number 243 : TUESDAY