Skip to content

Commit 14100f2

Browse files
committed
feat(day 162): compare workout and device energy consumption using joule conversion
1 parent 020a59a commit 14100f2

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""
2+
3+
Energy Consumption
4+
Given the number of Calories burned during a workout, and the number of watt-hours used by your electronic devices during that workout, determine which one used more energy.
5+
6+
To compare them, convert both values to joules using the following conversions:
7+
8+
1 Calorie equals 4184 joules.
9+
1 watt-hour equals 3600 joules.
10+
Return:
11+
12+
"Workout" if the workout used more energy.
13+
"Devices" if the device used more energy.
14+
"Equal" if both used the same amount of energy.
15+
"""
16+
17+
18+
import unittest
19+
20+
class EnergyConsumptionTest(unittest.TestCase):
21+
22+
def test1(self):
23+
self.assertEqual(compare_energy(250, 50), "Workout")
24+
25+
def test2(self):
26+
self.assertEqual(compare_energy(100, 200), "Devices")
27+
28+
def test3(self):
29+
self.assertEqual(compare_energy(450, 523), "Equal")
30+
31+
def test4(self):
32+
self.assertEqual(compare_energy(300, 75), "Workout")
33+
34+
def test5(self):
35+
self.assertEqual(compare_energy(200, 250), "Devices")
36+
37+
def test6(self):
38+
self.assertEqual(compare_energy(900, 1046), "Equal")
39+
40+
41+
def compare_energy(calories_burned, watt_hours_used):
42+
43+
workout_energy = calories_burned * 4184
44+
device_energy = watt_hours_used * 3600
45+
46+
if workout_energy > device_energy:
47+
return "Workout"
48+
elif device_energy > workout_energy:
49+
return "Devices"
50+
else:
51+
return "Equal"
52+
53+
54+
55+
if __name__ == "__main__":
56+
57+
unittest.main()

0 commit comments

Comments
 (0)