Question

PYTHON I need some basic python homework help! Write a program that prompts the user to...

PYTHON

I need some basic python homework help!

Write a program that prompts the user to enter a date (day, month, and year). Your program will print out the day of the week for that date.

You do not need to validate the input. That means you can assume:

  • the year will be entered as a four-digit number in the range 1900 through 2100 inclusive.
  • the month will be one of the strings "January", "February", . . ., "December".
  • the day will be an integer between 1 and 31 inclusive.
  • the user will not enter a date that doesn't exist (such as November 31, or February 29 in a non-leap year).

Algorithm:

This algorithm is called "Zeller's Congruence" after the person who developed it, Rev. Christian Zeller.

  • Let "a" be an integer based on the month of the year. For the months January through December, set a = 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10 (in that order).
  • Let "b" be the day of the month, exactly as entered by the user.
  • Let "c" be the last two digits of the year; for instance, if the year is 2018, c should equal 18. Important exception: if the month is January or February, subtract one from the year first. (In order to handle leap years correctly, the algorithm treats January and February as though they are the last two months of the previous year. That's why you do the assignments for "a" in that funny way.)
  • Let "d" be the first two digits of the year. (Make sure you calculate this AFTER you subtract one if you had to make any adjustments for January or February.)

Some sample calculations: for July 31, 1929, you should get a = 5, b = 31, c = 29, and d = 19. Similarly, for January 3, 1988, you should get a = 11, b = 3, c = 87, and d = 19.

Then calculate the following quantities:

    w = (13 * a - 1 ) // 5

    x = c // 4

    y = d // 4

    z = w + x + y + b + c - 2 * d

    r = z % 7

    r = (r + 7) % 7 [to take care of negative values of r]

If you did this correctly, r gives you the day of the week. r = 0 represents Sunday, r = 1 represents Monday, and so on.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#Zeller Congruence

def day(r):
   return {

0 : "Sunday",
1 : "Monday",
2 : "Tuesday",
3 : "Wednesday",
4 : "Thursday",
5 : "Friday",
6 : "Saturday"
}[r]

month=input("Enter Month-")
date=int(input("Enter date-"))
year=int(input("Enter year-"))
monthValue = {'January': 11 , 'February': 12,'March':1,'April':2,'May':3,'June':4,'July':5,'August':6,'September':7,'October':8,'November':9,'December':10} #python dictionary is created according to the value of every month.

a=monthValue.get(month)
b=date

if month=='January' or month=='February':
   year=year-1
c=year%100 #to get the last 2 digits of the year

d=year//100 #to get the first 2 digits of the year

w=(13*a-1)//5
x=c//4
y=d//4
z=w+x+y+b+c-2*d
r=z%7
r=(r+7)%7

print(day (r)) # the value r is a integer to get the corresponding day of the week the above function day is created.

If you found this helpful please upvote.

Add a comment
Know the answer?
Add Answer to:
PYTHON I need some basic python homework help! Write a program that prompts the user to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in python Worth 5 points (Science: day of the week) Zeller's congruence is an algorithm developed...

    in python Worth 5 points (Science: day of the week) Zeller's congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is h= (q + 26(m+1)//10 + k + k//4 +j//4 +5j) % 7 where - h is the day of the week (0: Saturday, 1: Sunday, 2: Monday, 3: Tuesday, 4: Wednesday, 5: Thursday, 6: Friday). - is the day of the month. m is the month (3: March, 4: April, ...,...

  • in python Write a program that reads the date of birth from the user as 3...

    in python Write a program that reads the date of birth from the user as 3 integer values (day, month, year) and then computes and prints their exact age in days. You need to take into account the leap You may not use any built-in functions related to date and time! Example: Someone born on 01/01/2000 is 365 days * 18 years + 5 days (since the years 2000, 2004, 2008, 2012, and 2016 are all leap years) + 352...

  • Need help implementing this Java class (Science: day of the week) Zeller's congruence is an algorithm...

    Need help implementing this Java class (Science: day of the week) Zeller's congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is h = (q + (26 * (m + 1)) / 10 + k + k / 4 + j / 4 + 5 * j) % 7 where h is the day of the week (0: Saturday, 1: Sunday, 2: Monday, 3: Tuesday, 4: Wednesday, 5: Thursday, 6: Friday). q...

  • C Programming Quesition (Structs in C): Write a C program that prompts the user for a...

    C Programming Quesition (Structs in C): Write a C program that prompts the user for a date (mm/dd/yyyy). The program should then take that date and use the formula on page 190 (see problem 2 in the textbook) to convert the date entered into a very large number representing a particular date. Here is the formula from Problem 2 in the textbook: A formula can be used to calculate the number of days between two dates. This is affected by...

  • Write a python program that does the following. a. It asks the user to enter a...

    Write a python program that does the following. a. It asks the user to enter a 5-digit integer value, n. b. The program reads a value entered by the user. If the value is not in the right range, the program should terminate. c. The program calculates and stores the 5 individual digits of n. d. The program outputs a “bar code” made of 5 lines of stars that represent the digits of the number n. For example, the following...

  • 1. Write a Python program that will determine if the user can vote or not. The...

    1. Write a Python program that will determine if the user can vote or not. The program will ask the user to enter integer numbers that represent year, month, and day of birth. Also, the program will ask the user to enter the current year, current month, and current day. The program will determine if the user is allowed to vote or not. If the user age is greater than or equal 18 then the program will print the following...

  • I need help with a project, I’ve seen many answers in C++, but i need it to be in swift, thank you!

    I need help with a project, I’ve seen many answers in C++, but i need it to be in swift, thank you! Write a program that asks the user to enter a date (e.g. July 4, 2008) and will return the day of the week that corresponds to that date. Your program should take the input in numeric form, thus the input prompt should be as follows: Please enter a date below: Enter month (1-12): Enter day (1-31) Enter year...

  • USING PYTHON. (Science: day of the week) Zeller’s congruence is an algorithm developed by Christian Zeller...

    USING PYTHON. (Science: day of the week) Zeller’s congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is h = (q + 26(m+1)//10 + k + k//4 +j//4 +5j) % 7 where - h is the day of the week (0: Saturday, 1: Sunday, 2: Monday, 3: Tuesday, 4: Wednesday, 5: Thursday, 6: Friday). - q is the day of the month. - m is the month (3: March, 4: April, ...,...

  • IN PYTHON, Write a program that reads a string from the user containing a date in...

    IN PYTHON, Write a program that reads a string from the user containing a date in the form mm/dd/ yyyy. It should print the date in the form April 12, 2017. Hint: Get the "mm" from the user entered date "mm/dd/yyyy", then convert the "mm" into a month number. You may use an list month_list = ['January', 'February','March','April', 'May','June', 'July','August', 'September', 'October', 'November', 'December']. Use the month number you got from "mm" to get the month name.

  • Write a program named CheckMonth2 that prompts a user to enter a birth month and day....

    Write a program named CheckMonth2 that prompts a user to enter a birth month and day. Display an error message that says Invalid date if the month is invalid (not 1 through 12) or the day is invalid for the month (for example, not between 1 and 31 for January or between 1 and 29 for February). If the month and day are valid, display them with a message. For example, if the month entered is 2, and the day...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT