0

Check50 says I am returning '2' but I do not think this is the case. I have also tried changing the order in which I print/return to see if it is expecting something different the error messages are all the same. Bellow is the code and the check50 output

C_LIGHT = 300000000

def main():
    ##prompt the user for input
    ##assuming the user inputs integer per instructions
    user_in = int(input("Input a mass in kg to Calculate E=Mc^2\n"))
    print(mass_to_energy(user_in))

def mass_to_energy(user_in):
    ##Calculating e=mc^2
    ## outputs the equivalent number of Joules as an integer
    ##print(user_in * (C_LIGHT ** 2))
    return (user_in * (C_LIGHT ** 2))

main()
Results for cs50/problems/2022/python/einstein generated by check50 v3.3.8
:) einstein.py exists
:( input of 1 yields output of 90000000000000000
    expected "90000000000000...", not "2"
    Seems like your output might not be the right number!
:( input of 14 yields output of 1260000000000000000
    expected "12600000000000...", not "2"
    Seems like your output might not be the right number!
:( input of 50 yields output of 4500000000000000000
    expected "45000000000000...", not "2"
    Seems like your output might not be the right number!
1
  • In my case, I was using two prints, so keeping one in main did the trick on this error. Check that the output is int, and the formula, the formula I used was little different. My advice, try to check for the formula E =mc2 in other post that could help you on writing it differently. Commented Jan 18 at 23:53

2 Answers 2

1

You have a few minor problems which may be causing your failure:

  • in your print statement you should be converting the result of the math to a string:
    print(str(mass_to_energy(user_in)))

  • The program expects specific prompts for input and output before the numbers and you are not providing those prompts, that may or may not cause an issue.

  • This is more of an improvement but if you are going to write a main function you should have it called conditionally so that your file can be imported properly this will help you later, and might not impact this problem passing the test

if __name__ == "__main__":
    main()
1
  • Unfortunately changing the int to a string before printing did not yield any better results and the error output remains the same: :) einstein.py exists :( input of 1 yields output of 90000000000000000 expected "90000000000000...", not "2" Seems like your output might not be the right number! :( input of 14 yields output of 1260000000000000000 expected "12600000000000...", not "2" Seems like your output might not be the rig
    – ifajardo
    Commented Sep 24, 2023 at 20:57
1

Figured out the problem!!! My original prompt read: "Input a mass in kg to Calculate E=Mc^2" , and I have to look into WHY but the ^2 was causing problems. I changed my code to "Input a mass in kg to Calculate E=Mc*c" and it's fixed

1
  • I am happy to learn that it worked for you. The answer has been deleted and a moderator told not to share answers. I do not know if how we are going to use this platform, if we cannot help? May be there is some other way of indirectly helping one another in the future :) Commented Sep 27, 2023 at 16:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .