12
0/8

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("\nYour 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]

Develop code Questions

Practise Edexcel GCSE Computer Science Develop code with exam-style questions for GCSE Computer Science. 57 questions 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, 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

Develop code Questions

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