Skip to content

Course home

Sign up

Develop code

EasyMediumHard
123456789101112131415
Question 7

A program is being developed to manage a list of ice cream flavours stored in a one-dimensional array.

The user is shown a menu of options. When the user chooses an option, the program performs that task. The program loops until the user chooses the exit option.

You are provided with the following incomplete Python code:

import random

# Global array of ice cream flavours
flavours = ["Vanilla", "Chocolate", "Strawberry", "Mint Choc Chip", "Salted Caramel"]

def displayMenu():
    print("
--- ICE CREAM MENU ---")
    print("1. Get Random Flavour")
    print("2. Add New Flavour")
    print("3. Exit")

def getChoice():
    # TODO: Complete this subprogram
    # Allow the user to enter a menu option number (no validation required)
    # Return the choice to the main program
    pass

def getFlavour():
    # TODO: Complete this subprogram
    # Use a random number as an index into the flavours array
    # Return the flavour to the main program
    pass

def addFlavour():
    # TODO: Complete this subprogram
    # Allow the user to enter a new ice cream flavour
    # Add the new name to the end of the flavours array
    pass

# --- Main Program ---
# TODO: Complete the main program loop
# Loop until the user chooses option 3 (Exit)
# Call the correct subprograms based on the user's choice
# Display the flavour returned from the getFlavour() subprogram
# Tell the user when an inputted option is not on the menu (invalid choice)

Amend the code to fully implement these subprograms and the main program logic.

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