SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
.selections
Exercise:
Programming Excercises
Question:5 | ISBN:978013274719 | Edition: 6

Question

(Find future dates) Write a program that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is 1, ..., and Saturday is 6). Also prompt the user to enter the number of days after today for a future day and display the future day of the week. Here is a sample run:

Enter today's day: 1
Enter the number of days elapsed since today: 3
Today is Monday and the future day is Thursday
 

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

#Prompt the user to give input
print("Enter todays date: ")
date = int(input())
print("Enter the number of days elapsed since today: ")
elapsed = int(input())
future_date = int((date + elapsed) % 7)
day_of_week = ""
#using Switch case from dictionaries
switcher={0:"Sunday",
          1: "Monday",
          2:"Tuesday",
          3:"Wednesday",
          4:"Thursday",
          5:"Friday",
          6: "Saturday"}
#Display the results
if (future_date == 0):
    print("Todays is %s and the future day is Sunday"%switcher.get(date))
elif(future_date == 1):
    print("Todays is %s and the future day is Monday"%switcher.get(date))
elif(future_date == 2):
    print("Todays is %s and the future day is Tuesday"%switcher.get(date));
elif(future_date == 3):
    print("Todays is %s and the future day is Wednesday"%switcher.get(date))
elif(future_date == 4):
    print("Todays is %s and the future day is Thursday"%switcher.get(date))
elif(future_date == 5):
    print("Todays is %s and the future day is Friday"%switcher.get(date));
elif(future_date == 6):
    print("Todays is %s and the future day is Saturday"%switcher.get(date))

Output:

Enter todays date: 
1
Enter the number of days elapsed since today: 
3
Todays is Monday and the future day is Thursday

0 0

Discussions

Post the discussion to improve the above solution.