0

write a program that asks the user the day number in a year in 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

22nd Aug 2016, 3:21 AM
Dibyendu Das
Dibyendu Das - avatar
3 Réponses
+ 1
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])
24th May 2023, 10:39 AM
Prantik Sarkar
Prantik Sarkar - avatar
0
def D(firstDay, dayNumber): days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] firstIndex = days.index(firstDay) endIndex = (firstIndex + int(dayNumber) - 1) % 7 return days[endIndex] year = input("Year: ") firstDay = input("First day of the year (e.g. 'Monday'): ") dayNumber = input("Day number: ") print(D(firstDay, dayNumber))
9th Jul 2020, 7:10 AM
Pranav Tyagi
Pranav Tyagi - avatar
- 1
what about February 29 ? Just use datetime, it may be more efficient ?
30th Aug 2016, 10:23 PM
Amaras A
Amaras A - avatar