MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / potential_energy

Function potential_energy

physics/potential_energy.py:31–55  ·  view source on GitHub ↗

>>> potential_energy(10,10) 980.665 >>> potential_energy(0,5) 0.0 >>> potential_energy(8,0) 0.0 >>> potential_energy(10,5) 490.3325 >>> potential_energy(0,0) 0.0 >>> potential_energy(2,8) 156.9064 >>> potential_energy(20,100) 19613.3

(mass: float, height: float)

Source from the content-addressed store, hash-verified

29
30
31def potential_energy(mass: float, height: float) -> float:
32 # function will accept mass and height as parameters and return potential energy
33 """
34 >>> potential_energy(10,10)
35 980.665
36 >>> potential_energy(0,5)
37 0.0
38 >>> potential_energy(8,0)
39 0.0
40 >>> potential_energy(10,5)
41 490.3325
42 >>> potential_energy(0,0)
43 0.0
44 >>> potential_energy(2,8)
45 156.9064
46 >>> potential_energy(20,100)
47 19613.3
48 """
49 if mass < 0:
50 # handling of negative values of mass
51 raise ValueError("The mass of a body cannot be negative")
52 if height < 0:
53 # handling of negative values of height
54 raise ValueError("The height above the ground cannot be negative")
55 return mass * g * height
56
57
58if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected