Created
January 2, 2024 23:33
-
-
Save se7enack/667741e2b8bfa3079c4e539d80fab0fc to your computer and use it in GitHub Desktop.
Mathematically calculates Pi Day's day-of-the-week for a given year
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
def day(x): | |
days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] | |
return days[x] | |
def century(y): | |
startdays = [0, 5, 3, 2] | |
centurycounter = 0 | |
for i in range(17, 21): | |
if y == i: | |
return startdays[centurycounter] | |
centurycounter = centurycounter + 1 | |
def output(): | |
print("\n<><><><><><><><><><><><><><><><><><><><><>") | |
print("In", year, "pi day (3/14) falls on a", day(dotw) + ".") | |
print("<><><><><><><><><><><><><><><><><><><><><>\n") | |
try: | |
year = int(input('Enter a 4 digit year between 1700 & 2099: ')) | |
if len(str(year)) == 4: | |
year = str(year) | |
cen, dec = int(year[:len(year)//2]), int(year[len(year)//2:]) | |
c = century(cen) | |
dotw = int(dec / 4 + dec + c) % 7 | |
output() | |
except: | |
print("Error: Only excepts years between 1700 & 2099") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment