Home > Net >  Looking for some help on an assignment question regarding a function
Looking for some help on an assignment question regarding a function

Time:12-17

I'm fairly new to python and i'm working on a problem for a school project. I feel im making progress but i'm not sure what to do next. The question is:

Write a function that takes mass as input and returns its energy equivalent using Einstein’s famous E = mc 2 equation. Test it with at least 3 different mass values. Write the program so that it can take the mass in kilograms as a commandline argument.

import sys
import math

m = float(sys.argv)

c = float(299792458)

def einstein_equation(m, c):
    result = m * (math.pow(c, 2))
    return result

e = einstein_equation(m, c)
print e

CodePudding user response:

just make it simple man, no need for sys.argv

and no need for math.pow

just:

c = float(7382)

def einstein_equation(m, c):
    return m * (c*c)
for _ in range(3):
    m = float(input("MASS : "))
    e = einstein_equation(m, c)
    print (e)

CodePudding user response:

You don't need libary for powering and just add index for sys.argv

import sys

m = int(sys.argv[1])
c = 299792458

print(m*c**2)
  • Related