Am I Doing This Correctly? Beginner Python

Am I Doing This Correctly? Beginner Python
  1. Prompt user for X(which is Mr Jones weight in Kilo Grams)
  2. calculate the graviational force(F) and acceleration due to gravity(g) caused by the gravitational force exerted on him by the earth.

gravitational force(F): F= G (m1)(m2) / (r**2) and F = mg

Universal gravitational constant: G= 6.67300 X 10 **-11

check to see that the resulting value of (g) is close to 9.8 m/s**2

other variables:

radius_earth = 6378 * 10 ** 3

mass_earth = 5.9742 * 10 ** 24 # m1

now this is this what I am suppose to get? 9.8 m/s**2???????

this is what I put:

radius_earth = 6378 * 10 ** 3

mass_earth = 5.9742 * 10 ** 24  # m1

jones_mass = input("Mr Jones Mass in kilograms is: ")  #m2

float_mass = float(jones_mass)

gravity = 6.67300 * 10 ** -11

force = gravity * mass_earth * float_mass / (radius_earth ** 2) 
 #gravitational force

print(force)

because when I input 1 I get this result:

Mr Jones Mass in kilograms is: 1

9.80013035755848

>>> 

Am I doing this correctly since it says the answer should be equivalent to 9.8 ms/**2?

4

3 Answers

Yes, it looks like you are doing it correctly. As for the rounding errors (which I understand may be the point of your question), the recommended reading is: What Every Computer Scientist Should Know About Floating-Point Arithmetic (it applies not only to Python).

In order to provide some precision in Python you could use the decimal module.

0

First your most likely in my class cs10 lol. Second everything is perfect expect your print statement..

change it to:

print(format(force,'.1f'),"m/s^2")

Also instead of having a variable just to change jones_mass to a float you can declare that jones's mass will be a float inside your input statement:

before:

jones_mass = input("Mr Jones Mass in kilograms is: ")
float_mass = float(jones_mass)

after:

 jones_mass = float(input("Mr Jones Mass in kilograms is: "))

accel_gravity = 9.81 accel_gravity = float((G * M)/(dist_center**2))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.