Skip to content

Course home

Sign up

Develop code

EasyMediumHard
123456789101112131415
Question 13

A program is needed to monitor pressure readings in a chemical reactor. The program must meet the following requirements:

  • accept only integer pressures from 100 to 800 kPa, inclusive
  • print 'Hazardous pressure' if the input is outside the permitted range. You can assume only numeric inputs will be entered
  • print the input pressure followed by ' is a multiple of 50', if the pressure is divisible by 50
  • print the input pressure followed by ' is not a multiple of 50', if the pressure is not divisible by 50.

Here is the current, buggy version of the Python code:

pressure = input("Enter pressure (kPa): ")

if pressure < 100 and pressure > 800:
    print("Hazardous pressure")

if pressure % 50 == 0:
    print(pressure + " is a multiple of 50")
else:
    print(pressure + " is not a multiple of 50")

Amend the code to:

  1. Fix the runtime error caused by inputting a valid integer (e.g., entering 150) to ensure proper type conversion.
  2. Fix the logic error in the range condition so that invalid inputs are correctly detected.
  3. Fix the control flow logic error so that the program does not perform division checking if the pressure is outside the permitted range.
  4. Fix the runtime error and formatting issues in the final print statements so that the input pressure is correctly concatenated or formatted in the output text.

Do not add any additional functionality or validation.

[13]
Markscheme

Develop code Questions

  1. GCSE
  2. /Computer Science
  3. /Develop code

51 exam-style questions on Edexcel GCSE Computer Science Develop code, covering Decomposition and abstraction to solve problems, Read, write, analyse and refine programs, Converting algorithms into programs, Techniques for readable, maintainable code, Identifying and correcting program errors, and Evaluating program fitness and efficiency. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank