Computer Science
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.
Answer
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])
Output
Enter day number: 243
First day of year: FRIDAY
Day on day number 243 : TUESDAY
Related Questions
Write a Python program that calculates and prints the number of seconds in a year.
Write a Python program that accepts two integers from the user and prints a message saying if first number is divisible by second number or if it is not.
One foot equals 12 inches. Write a function that accepts a length written in feet as an argument and returns this length written in inches. Write a second function that asks the user for a number of feet and returns this value. Write a third function that accepts a number of inches and displays this to the screen. Use these three functions to write a program that asks the user for a number of feet and tells them the corresponding number of inches.
Write a program that reads an integer N from the keyboard computes and displays the sum of the numbers from N to (2 * N) if N is nonnegative. If N is a negative number, then it's the sum of the numbers from (2 * N) to N. The starting and ending points are included in the sum.