Jump to content

Hello, I have a really simple problem im looking to solve, but am having the darnedest time figuring out. The problem is this: The method 'energy' should evaluate the formula E = mc^2, where the variables 'm' and 'c' are passed in as parameters and E (energy) is the return value. 

The solution parameter is listed as :

 def energy(m, c):
    return 

 

Any help would be greatly appreciated!

Link to comment
https://linustechtips.com/topic/893324-python-help/
Share on other sites

Link to post
Share on other sites

E = mc 2 definition. An equation derived by the twentieth-century physicist Albert Einstein, in which E represents units of energy, m represents units of mass, and c 2 is the speed of light squared, or multiplied by itself.

 

I think the part that you are missing is where the speed of light is squared.

 

Link to comment
https://linustechtips.com/topic/893324-python-help/#findComment-11011793
Share on other sites

Link to post
Share on other sites

19 hours ago, Angelz&Airwavez said:

where the variables 'm' and 'c' are passed in as parameters

Not really do to with the coding but why would you pass c as a parameter when c is a constant? 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
https://linustechtips.com/topic/893324-python-help/#findComment-11014696
Share on other sites

Link to post
Share on other sites

On 05/02/2018 at 1:37 PM, vorticalbox said:

Not really do to with the coding but why would you pass c as a parameter when c is a constant? 

Yeah that'd probably make a lot more sense as a global constant somewhere.

 

On 04/02/2018 at 6:57 PM, Technicolors said:

you can also do 'from math import pow'

 

then pow(c, 2)

I usually either import everything ( from math import * ) from a library or just import the library ( import math ) and use math.pow().

 

Also for the OP, I'd avoid using single letter variable names. While in this case it doesn't really matter since it's a common enough formula that everyone should be able to know what m stands for, it's better to be in the habit to make things human readable. Basically write mass instead of m.

Link to comment
https://linustechtips.com/topic/893324-python-help/#findComment-11020142
Share on other sites

Link to post
Share on other sites

c = 299792458

energy = lambda m: m + c*c
print(energy(1))

 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
https://linustechtips.com/topic/893324-python-help/#findComment-11020300
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×