I'm working through some programing exersizes and one is to create a program which counts calories for a user and returns calories burned at specific times in minutes(10,15,20,25,30). The user burns calories at a constant rate of 3.9 cal/min:
import time as t def calorie_count(workout_time): calories_burned = CALORIES_PER_MINUTE * workout_time print("you've burned ", calories_burned, " calories in ", workout_time, " minutes!") return CALORIES_PER_MINUTE = 3.9 t.sleep(1) calorie_count(10) t.sleep(1) calorie_count(15) t.sleep(1) calorie_count(20) t.sleep(1) calorie_count(25) t.sleep(1) calorie_count(30) input("press any key to end the program")
This is what I came up with that worked. I imagined something cooler and I did all the flowcharting that I needed to complete with a few functions, problem is I don't know enough about the date time module or time in python to actually implement what I "engineered":
The issue I had was I couldn't just subtract "now" from my "start time" to get an "amount of minutes passed since the start". What I wanted to do was create a case/switch function which would run my "calorie\_count" function at the specified intervals and print calories burned. I'm pretty sure I've seen it done in some books(I'm reading PACKT's Learn Python Programming) but can't find it currently and the Python datetime documentation isn't easy.to ttp://easy.to understand for a beginner So, my question is, \#how do I subtract time and get a integer I can use #dev #programming #technology oaw() source