Page 1 of 1

You are given a file script.py [DO NOT MODIFY THIS FILE] • line 2: import the class_module module • line 4: create an in

Posted: Thu May 05, 2022 12:59 pm
by answerhappygod
You Are Given A File Script Py Do Not Modify This File Line 2 Import The Class Module Module Line 4 Create An In 1
You Are Given A File Script Py Do Not Modify This File Line 2 Import The Class Module Module Line 4 Create An In 1 (79.55 KiB) Viewed 25 times
You are given a file script.py [DO NOT MODIFY THIS FILE] • line 2: import the class_module module • line 4: create an instance veggie_calories that belongs to a class Calory (it has 15 calories for lettuce, 23 calories for spinach, 14 calories for celery, 12 calories for cucumber, and 16 calories for radish as shown in the table below, measured per 100g). • line 6: execute the method calculate_total on the veggie_calories object. (it has 200g celery and 360g cucumber) • line 7: execute the method calculate_total on the veggie_calories object. (it has 150 lettuce, 50g spinach and 300g radish) Vegetable Measurement Calories lettuce 100g 15 spinach 100g 23 celery 100g 14 cucumber 100g 12 radish 100g 16
+ class_module.py script.py L# DO NOT MODIFY THIS FILE import class_module as cn B veggie_calories - cm.Calory(15, 23, 14, 12, 16) print("The total calories for your vegetable intake is ".format(veggie_calories.calculate_total print("The total calories for your vegetable intake is ".format(veggie_calories.calculate_total # DO NOT MODIFY THIS FILE (celery-200, cucumber-360))) (lettuce-150, spinach-50, radish-300)))
Your Task Implement a class_module.py which MUST have the following three components: 1. A class Calory 2. [Under the class Calory] A __init__ method (function) to assign the calory values for variables/attributes named, lettuce, spinach, celery, cucumber and radish. (hint: check how we did in Lesson 1.1, Part 3) 3. [Under the class Calory] A calculate_total method (function) that 1. receives the measurement (in grams) for each type of vegetable from the function call (default is 0 for each) 2. calculates the total calories of the vegetables (NOTE that the number and calories of each vegetable are given in the script.py) 3. returns the total calories of the vegetables as a float. Your program should output the following. [user@sahara ~]$ python script.py The total calories for your vegetable intake is 71.2 The total calories for your vegetable intake is 82.0