Data types and structures

EasyMedium
12345678910
Question 7
Medium

A program is being written to generate a random discount percentage for a retail shop's promotional event. The discount must be a random whole number between 10 and 40 inclusive.

An incomplete Python program is provided below:

# Program to generate a random discount percentage

# TODO 1: Import the random library

# TODO 2: Create a constant called MAX_DISCOUNT and set it to 40
MIN_DISCOUNT = 10

# TODO 3 & 4: Create a variable called discount_applied and assign
# the result of a library call to generate a random integer
# between MIN_DISCOUNT and MAX_DISCOUNT (inclusive)

# TODO 5: Display the message "Your discount percentage: " followed
# by the value of discount_applied

Amend the code by completing the sections marked with TODO to:

  • import the random library
  • create a constant called MAX_DISCOUNT with the value 40
  • create a variable called discount_applied
  • use a library call to generate a random number between MIN_DISCOUNT and MAX_DISCOUNT inclusive, assigning it to discount_applied
  • display the string message "Your discount percentage: " and the value of discount_applied on the screen

Do not add any additional functionality.

[7]

Data types and structures Questions

  1. GCSE
  2. /Computer Science
  3. /Data types and structures