Morning Routine
Objective:
Find and correct code. There are two errors that must be corrected. One is a syntax error. The other error causes the program to always think it’s Thursday.
import datetime
import time
import random
#weekDays is a tuple. Monday is weekdays[0]
weekDays = ("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")
#Workout is a Dictionary
Workout={1:"Run",2:"Row",3:"Elliptical",4:"Weights",5:"Swim"}
WakeHour=5
WakeMinute=0
#GetDayOfWeek is a function that returns the day of the week
#if today is Monday then:
# x = GetDayOfWeek
# x would be "Monday"
def GetDayOfWeek():
todaysDate=datetime.date.today()
dayofweek=todaysDate.weekday()
return(weekDays[dayofweek])
def countdown(t,workoutname):
print("Time remaining in your:",workoutname )
while t:
mins, secs = divmod(t, 60)
timeformat = '{:02}:{:02}'.format(mins, secs)
print(timeformat, end='\r')
time.sleep(1)
t -= 1
def Run(timetorun):
countdown(timetorun,"Run")
def Swim(timetoswim):
countdown(timetoswim,"Swim")
def Row(timetorow):
countdown(timetorow,"Row")
def Elliptical(timetoelliptical):
countdown(timetoelliptical,"Elliptical")
def weights(timetorun):
countdown(timetorun,"Weights)
def WorkOut_MWF(HowMuchTime):
#Monday Wednesday and Fridays are either
#Run / Swim or Elliptical / Swim
#Program chooses between run and elliptical
#and divides the time evenly
HowLong=HowMuchTime/2
RowOrElliptical=random.randint(1,2)
if(RowOrElliptical==2):
#You Run
Run(HowLong)
else:
Elliptical(HowLong)
Swim(HowLong)
def WorkOut_TueThurs(HowMuchTime):
#Tuesday / Thursday we do Three Exercises
#Row or Elliptical/ Weights / Swim
HowLong=HowMuchTime/3
x=random.choice([2,3])
print('Today your gonna: ',Workout[x])
if x==2:
Row(HowLong)
else:
Elliptical(HowLong)
Swim(HowLong)
def RestDay():
print("ahhhhh, Time to relax")
def main():
x=GetDayOfWeek()
x='Thursday'
print("Today is: ",x)
TimeAvailable=input("How much time do you have? ")
iTimeAvailable=int(TimeAvailable)
if x in ["Monday","Wednesday","Friday"]:
WorkOut_MWF(iTimeAvailable)
elif x in ["Tuesday", "Thursday"]:
WorkOut_TueThurs(iTimeAvailable)
else:
RestDay()
main()