Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Previously, you wrote a class called ExerciseSession that had three attributes: an exercise name, an intensity, and a duration.
- Add a new method to that class called calories_burned.
- calories_burned should have no parameters (besides self, as every method in a class has). It should return an integer representing the number of calories burned according to the following formula:
- If the intensity is "Low", 4 calories are burned per minute.
- If the intensity is "Moderate", 8 calories are burned per minute.
- If the intensity is "High", 12 calories are burned per minute.
- '''
- #Add your code here!
- class ExerciseSession:
- def __init__(self, exercise, intensity, duration):
- self.exercise = exercise
- self.intensity = intensity
- self.duration = duration
- def get_exercise(self):
- return self.exercise
- def get_intensity(self):
- return self.intensity
- def get_duration(self):
- return self.duration
- def set_exercise(self, name):
- self.exercise = name
- def set_intensity(self, newintensity):
- self.intensity = newintensity
- def set_duration(self, newduration):
- self.duration = newduration
- def calories_burned(self):
- if self.intensity == "Low":
- calories = 4 # or return 4*self.duration
- elif self.intensity == "Moderate":
- calories = 8 # or return 8*self.duration
- elif self.intensity == "High":
- calories = 12 # or return 12*self.duration
- return calories * self.duration
- #in the model answer, should multiply the self.duration at each condition
- #If your code is implemented correctly, the lines below will run error-free. They will result in the following output to the console:
- #240
- #360
- new_exercise = ExerciseSession("Running", "Low", 60)
- print(new_exercise.calories_burned())
- new_exercise.set_exercise("Swimming")
- new_exercise.set_intensity("High")
- new_exercise.set_duration(30)
- print(new_exercise.calories_burned())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement