Skip to content

#9191 mass energy eqivalence #9217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 31 commits into from
Closed
Changes from 23 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4efd5ec
Create mass_energy_equivalence.py
mhsuhail00 Oct 1, 2023
6acde00
Update mass_energy_equivalence.py
mhsuhail00 Oct 1, 2023
63cf15d
Update mass_energy_equivalence.py
mhsuhail00 Oct 1, 2023
b7773d2
Update mass_energy_equivalence.py
mhsuhail00 Oct 1, 2023
79ccf5a
Update mass_energy_equivalence.py
mhsuhail00 Oct 1, 2023
5a3e966
Update mass_energy_equivalence.py
mhsuhail00 Oct 1, 2023
fdb0da5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 1, 2023
4bc3fa1
Update mass_energy_equivalence.py
mhsuhail00 Oct 1, 2023
55c8e1f
Update mass_energy_equivalence.py
mhsuhail00 Oct 1, 2023
dbd065c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 1, 2023
90f562f
Update mass_energy_equivalence.py
mhsuhail00 Oct 1, 2023
32ca83f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 1, 2023
396805b
Apply suggestions from code review
mhsuhail00 Oct 1, 2023
46268c1
Apply suggestions from code review
mhsuhail00 Oct 1, 2023
fc5b639
Apply suggestions from code review
mhsuhail00 Oct 1, 2023
e2438a6
Apply suggestions from code review
mhsuhail00 Oct 1, 2023
456f39c
Update mass_energy_equivalence.py
mhsuhail00 Oct 1, 2023
aedc65a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 1, 2023
832d481
Update mass_energy_equivalence.py
mhsuhail00 Oct 1, 2023
888ba00
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 1, 2023
393b522
Update mass_energy_equivalence.py
mhsuhail00 Oct 1, 2023
2ae7736
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 1, 2023
7bca844
Update mass_energy_equivalence.py
mhsuhail00 Oct 1, 2023
11a02a6
Update mass_energy_equivalence.py
mhsuhail00 Oct 1, 2023
7542a9e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 1, 2023
614a8ec
Update mass_energy_equivalence.py
mhsuhail00 Oct 1, 2023
733fdbe
Update mass_energy_equivalence.py
mhsuhail00 Oct 1, 2023
a79fbcc
Update mass_energy_equivalence.py
mhsuhail00 Oct 1, 2023
91b1445
Update mass_energy_equivalence.py
mhsuhail00 Oct 1, 2023
39969f4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 1, 2023
9c1e532
Update mass_energy_equivalence.py
mhsuhail00 Oct 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions physics/mass_energy_equivalence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Mass-energy equivalence
Reference: https://en.wikipedia.org/wiki/Mass%E2%80%93energy_equivalence

Here it defines a Function to calculate energy(in joules) equivalent of a given
mass(in kilograms) using Einstein's Mass-energy equivalence equation E=mc^2
where m is mass and c is the speed of light in vaccume(a constant value)
in meter per second.

The function takes a single argument mass(in kg) having datatype float and
returns the energy(in joule) having datatype float
Comment on lines +10 to +11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a description of the function, so please put it in the function's docstring rather than the header string.

"""


def calculate_energy(mass: float) -> float:
"""
get energy equivalent of given mass in joules:
>>> calculate_energy(1.2)
1.0785062144841811e+17
>>> calculate_energy(3.0)
2.6962655362104528e+17
>>> calculate_energy(5)
449377589368408820
>>> calculate_energy(-5)
Traceback (most recent call last):
...
raise TypeError("Mass cannot be negative")
TypeError: Mass cannot be negative
"""
if mass < 0:
raise TypeError("Mass cannot be negative")
speed_of_light = 299792458
energy = mass * speed_of_light**2
return energy


if __name__ == "__main__":
mass = float(input("Enter mass (in kilograms): "))
energy = calculate_energy(mass)
print(f"Energy equivalent: {energy} joules")