Skip to content

Course home

Sign up

Develop code

EasyMediumHard
1234567891011121314151617
Question 5

A program is written for a chemical solvent selection system in a laboratory. It displays the names of available solvents, stored in an array. The user enters the number of tests they want to run. That number of solvents is selected randomly from the array and displayed.

Original Code (solvent_selector.py)

impor random

solventList = ["Ethanol", Acetone, "Water",
               "Hexane", "Toluene"]

print("Available solvents:")
for solvent in solventList
    print("- " + solvent)

numTests = int(input("How many solvent tests to run? "))

print("
Your random test sequence:")
for count in range(numTests - 1):
    index = random.
    selected = solventList[index + 1]
    print(selectd)

Amend the code to:

  • fix the syntax error on line 1 (impor random)
  • fix the syntax error on line 8 (for solvent in solventList)
  • complete line 16 to generate a random integer between 0 and 4 (index = random.)
  • complete line 3 to make all the solvent names be string data types (solventList = ...)
  • fix the IndexError on line 17 (selected = solventList[index + 1])
  • fix the NameError on line 18 (print(selectd))
  • fix the logic error on line 15 that causes one less solvent to be printed than is asked for (for count in range(numTests - 1):)
  • use white space to improve the readability of the code.

Do not change the basic functionality of the correct parts of the code. Do not add any additional features.

[8]
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