Skip to content

Course home

Sign up

Subprograms

EasyMediumHard
12345678910111213141516
Question 12

An agricultural enterprise is assessing the volume of grain that can be stored in different cylindrical silos.

The formula to calculate the volume of a cylinder is:

V=πr2h V = \pi r^2 h V=πr2h
  • V V\,V is the volume
  • π \pi\,π is the constant Pi
  • r r\,r is the radius of the circular base
  • h h\,h is the height of the cylinder

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_cylinder_volume():
    # Add parameters and calculation here
    pass

# Main program
radius = float(input("Enter the base radius (m): "))
height = float(input("Enter the height (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 radius and height 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 volume based on the input parameters.
  • The main program must print the volume, formatted to show exactly two decimal places (e.g. 124.50 or 50.27).

Do not add any additional functionality.

Save your amended code as Q05FINISHED.py

[8]
Markscheme

Subprograms Questions

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

29 exam-style questions on Edexcel GCSE Computer Science Subprograms, covering Built-in and user-devised subprograms, Functions versus procedures, and Global and local variables. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank