6Medium
0/10

A washer (flat ring) is cut out of a circular sheet of metal. A program is needed to calculate the surface area of the resulting washer. The image shows the completed washer in grey.

A diagram showing a concentric inner circle cut out of a larger outer circle. The remaining ring shape (the washer) is shaded in grey. The outer circle has radius R and the inner circle cutout has radius r.

The required formulae are:

area of outer circle=πR2 \text{area of outer circle} = \pi R^2 area of outer circle=πR2 area of inner circle=πr2 \text{area of inner circle} = \pi r^2 area of inner circle=πr2 surface area of washer=area of outer circle−area of inner circle \text{surface area of washer} = \text{area of outer circle} - \text{area of inner circle} surface area of washer=area of outer circle−area of inner circle
  • R R\,R is the radius of the outer circle
  • r r\,r is the radius of the inner circle
  • π \pi\,π is the constant Pi.

The table shows accurate test results for two sets of inputs.

InputOutput
Outer radius (RRR)Inner radius (rrr)
68Invalid input
104263.8937829015426

The program has these requirements:

  • the outer radius is an integer
  • the inner radius is an integer
  • the user inputs both the outer radius and the inner radius (no validation required)
  • the inner radius must be strictly smaller than the outer radius to make a valid washer
  • the variables supplied in the code file must be used.

Below is the content of the file Q03.py:

import math

outer_radius = int(input("Enter outer radius: "))
inner_radius = int(input("Enter inner radius: "))

# Calculate area
area_outer = math.pi * (outer_radius ** 2)
area_inner = math.pi * (inner_radius ** 2)

print(area_outer - area_inner)

Amend the code to meet the requirements of validating the dimensions and outputting the correct result or "Invalid input".

Do not change the functionality of the given lines of code.

Do not add any additional functionality.

Save your amended code file as Q03FINISHED.py

[10]

Input/output Questions

Practise Edexcel GCSE Computer Science Input/output with exam-style questions for GCSE Computer Science. 29 questions covering Accepting and responding to user input, Reading and writing CSV text files, Implementing validation, and Implementing authentication, 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

Input/output Questions

  1. GCSE
  2. /Computer Science
  3. /Input/output