2Hard
0/12

An astrophysics lab is developing software to calculate the escape velocity of various exoplanets.

The formula to calculate the escape velocity of a spherical celestial body is:

v=2GMRv = \sqrt{\frac{2GM}{R}}v=R2GM​​

  • vvv is the escape velocity in meters per second (m/s\text{m/s}m/s)
  • GGG is the universal gravitational constant, G=6.674×10−11 m3 kg−1 s−2G = 6.674 \times 10^{-11} \text{ m}^3 \text{ kg}^{-1} \text{ s}^{-2}G=6.674×10−11 m3 kg−1 s−2
  • MMM is the mass of the planet in kilograms (kg\text{kg}kg)
  • RRR is the radius of the planet in meters (m\text{m}m)

A program and subprogram have been started to carry out this calculation, but are incomplete.

Original code in file Q05.py:

# Q05.py - Unfinished program
# Do not change the existing input statements

def calculate_escape_velocity():
    # Add parameters and calculation here
    pass

# Main program
mass = float(input("Enter the mass of the planet (kg): "))
radius = float(input("Enter the radius of the planet (m): "))

# Call the subprogram and print the formatted result

Amend the program and subprogram to meet the following requirements:

  • The subprogram must work for any values of mass and radius passed as parameters. You can assume values passed to the subprogram will always be numbers. No validation is required.
  • The subprogram must calculate and return the escape velocity based on the input parameters using G=6.674×10−11G = 6.674 \times 10^{-11}G=6.674×10−11.
  • The main program must print the calculated velocity, formatted to show exactly three decimal places (e.g. 11186.273 or 2375.400).

Do not add any additional functionality.

Save your amended code as Q05FINISHED.py

[12]

Subprograms Questions

Practise Edexcel GCSE Computer Science Subprograms with exam-style questions for GCSE Computer Science. 29 questions covering Built-in and user-devised subprograms, Functions versus procedures, and Global and local variables, matched to the Edexcel GCSE Computer Science (1CP2) specification and written in Paper 1 and Paper 2 style. Every question includes a full worked solution and mark scheme, so you can see where marks are awarded rather than just whether you got the answer right.

PreviousNext

Subprograms Questions

  1. GCSE
  2. /Computer Science
  3. /Subprograms