Your weight is a measure of the amount of gravity exerted on your body by the planet Earth. On planet Earth, gravity has a value of 9.81 N/Kg (Newtons per kilogram). Because the Moon has about one-sixth of the gravity that Earth does, you would weigh less standing on it. On the Moon, gravity has a value of 1.622 N/Kg.
We can hence use the following formula to calculate your weight on the Moon:
For this challenge, we will write a short Python program, based on the Input / Process / Output model. Our program will:
- INPUT:
Ask the user to input their weight in kg and store this value in a variable called weightOnEarth. - PROCESS:
Apply the formula to calculate the equivalent lunar weight and store it in a variable called weightOnMoon. - OUTPUT:
Display the weight on the Moon on screen.
Python Code
Your Task:
Complete the above code to calculate and output the weight of the end-user on all of the following planets:
Planet / Celestial Body | Gravity (in N/Kg) |
Moon | 1.622 |
Mercury | 3.7 |
Venus | 8.87 |
Mars | 3.711 |
Jupiter | 24.79 |
Saturn | 10.44 |
Uranus | 8.69 |
Neptune | 11.15 |
Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area