Skip to content

Commit c6694c2

Browse files
committed
Adding double.py
1 parent 7ac2289 commit c6694c2

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

code/double.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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()

0 commit comments

Comments
 (0)