Skip to content

Commit 1514054

Browse files
committed
Python Future Date code snippets
1 parent 206aec5 commit 1514054

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

Python-Future-Date/credit.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import datetime
2+
import calendar
3+
4+
balance = 10000
5+
interest_rate = 13 * .01
6+
monthly_payment = 1000
7+
8+
today = datetime.date.today()
9+
days_in_current_month = calendar.monthrange(today.year, today.month)[1]
10+
days_till_end_month = days_in_current_month - today.day
11+
12+
start_date = today + datetime.timedelta(days=days_till_end_month + 1)
13+
end_date = start_date
14+
15+
while balance > 0:
16+
interest_charge = (interest_rate / 12) * balance
17+
balance += interest_charge
18+
balance -= monthly_payment
19+
20+
balance = round(balance, 2)
21+
if balance < 0:
22+
balance = 0
23+
24+
print(end_date, balance)
25+
26+
days_in_current_month = calendar.monthrange(end_date.year, end_date.month)[1]
27+
end_date = end_date + datetime.timedelta(days=days_in_current_month)

Python-Future-Date/subs.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import datetime
2+
import math
3+
4+
goal_subs = 150000
5+
current_subs = 85000
6+
subs_to_go = goal_subs - current_subs
7+
8+
avg_subs_day = 200
9+
days_to_go = math.ceil(subs_to_go / avg_subs_day)
10+
11+
today = datetime.date.today()
12+
13+
print(today + datetime.timedelta(days=days_to_go))

Python-Future-Date/weight.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import datetime
2+
3+
current_weight = 220
4+
goal_weight = 180
5+
avg_lbs_week = 2
6+
7+
start_date = datetime.date.today()
8+
end_date = start_date
9+
10+
while current_weight > goal_weight:
11+
end_date += datetime.timedelta(days=7)
12+
current_weight -= avg_lbs_week
13+
14+
print(end_date)
15+
print(f'Reached goal in {(end_date - start_date).days // 7} weeks')

0 commit comments

Comments
 (0)