Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download

📚 The CoCalc Library - books, templates and other resources

Views: 96165
License: OTHER
1
"""This module contains a code example related to
2
3
Think Python, 2nd Edition
4
by Allen Downey
5
http://thinkpython2.com
6
7
Copyright 2015 Allen Downey
8
9
License: http://creativecommons.org/licenses/by/4.0/
10
"""
11
12
from __future__ import print_function, division
13
14
from datetime import datetime
15
16
17
def main():
18
print("Today's date and the day of the week:")
19
today = datetime.today()
20
print(today)
21
print(today.strftime("%A"))
22
23
print("Your next birthday and how far away it is:")
24
#s = input('Enter your birthday in mm/dd/yyyy format: ')
25
s = '5/11/1967'
26
bday = datetime.strptime(s, '%m/%d/%Y')
27
28
next_bday = bday.replace(year=today.year)
29
if next_bday < today:
30
next_bday = next_bday.replace(year=today.year+1)
31
print(next_bday)
32
33
until_next_bday = next_bday - today
34
print(until_next_bday)
35
36
print("Your current age:")
37
last_bday = next_bday.replace(year=next_bday.year-1)
38
age = last_bday.year - bday.year
39
print(age)
40
41
print("For people born on these dates:")
42
bday1 = datetime(day=11, month=5, year=1967)
43
bday2 = datetime(day=11, month=10, year=2003)
44
print(bday1)
45
print(bday2)
46
47
print("Double Day is")
48
d1 = min(bday1, bday2)
49
d2 = max(bday1, bday2)
50
dd = d2 + (d2 - d1)
51
print(dd)
52
53
54
if __name__ == '__main__':
55
main()
56
57