forked from retswerb/500miles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path500miles.py
55 lines (46 loc) · 1.91 KB
/
500miles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#import
from datetime import date
#get current date
curDate = date.today()
#set target miles
annualMiles = 500
#count how many days since beginning of year (daysElapsed)
dateNewYear = date(2020, 12, 31)
testDate = date(2021, 12, 31) #use for testing if needed
daysElapsed = curDate - dateNewYear
daysGone = daysElapsed.days
#Calculate percentage (yearPercent = daysGone / 365)
yearPercent = daysGone/365
print("Today's date is", str(curDate) + ".")
print(daysGone, "days have gone by in 2021.")
#input number of miles run (milesRun)
#handle non-numbers gracefully
while True:
try:
milesRun = input("How many miles have you run this year? (Enter 'Miles' to change mileage goal from " + str(annualMiles) + " miles) ")
#change goal if needed
if milesRun == "Miles" or milesRun == "miles":
annualMiles = input("Enter your annual mileage goal: ")
annualMiles = float(annualMiles)
milesRun = 0
#back to accepting mileage input
else:
milesRun = float(milesRun)
break
except ValueError:
print("Please enter the number of miles you've run so far.")
continue
milesRun = round(milesRun, 2)
#calculate target (targetMiles = yearPercent * 500)
targetMiles = yearPercent*annualMiles
targetMiles = round(targetMiles, 2)
#compare milesRun to targetMiles
#print you are on target / above target / below target with amount over/under
if milesRun == targetMiles:
print("Whoa! You're exactly on target!")
elif milesRun < targetMiles:
milesBehind = round((targetMiles - milesRun), 2)
print("Time to get running! You're", milesBehind, "miles behind today's target,", targetMiles, "miles.")
elif milesRun > targetMiles:
milesAhead = round((milesRun - targetMiles), 2)
print("Great job! You're %s miles ahead of today's target, %s miles." % (milesAhead, targetMiles))