481# -------------------------------------------------------------------
2# Constants
3# -------------------------------------------------------------------
4MOON_GRAVITY = 1.62
5EARTH_GRAVITY = 9.80665
6
7# -------------------------------------------------------------------
8# Global variables
9# -------------------------------------------------------------------
10mass = 0.0
11weightOnEarth = 0.0
12weightOnTheMoon = 0.0
13layout = ""
14
15# -------------------------------------------------------------------
16# Subprograms
17# -------------------------------------------------------------------
18# weight = mass × gravitational field strength
19def calculateWeight(pMass, pGravity):
20return pMass * pGravity
21
22# -------------------------------------------------------------------
23# Main program
24# -------------------------------------------------------------------
25
26# ask user to input mass
27print("Welcome to the Earth and Moon weight calculator")
28print("=" * 47)
29mass = float(input("Enter the mass of an object (in Kg)"))
30
31# Calcuate weight on earth & moon
32weightOnEarth = calculateWeight(mass, EARTH_GRAVITY)
33weightOnTheMoon = calculateWeight(mass, MOON_GRAVITY)
34
35# Display results
36layout = "The weight on {} is {:.2f} N (newtons)"
37print(layout.format("Earth", weightOnEarth))
38print(layout.format("The Moon", weightOnTheMoon))
39
40# Challenges:
41# Answer each of the questions below next to where it says A)
42# e.g. Q) Write the symbol used for comments: A) #
43
44# Q1) Write the identifier of a constant: A)
45# Q2) Write the name of a user defined function: A)
46# Q3) What is the data type of the layout variable: A)
47# Q4) Name one parameter used in the code: A)
48# Q5) An arithmetic operator used in the code: A)