Data types and structures

EasyMedium
12345678910
Question 8
Medium

A program is being written to simulate a daily rainfall measurement in a dry region. The daily rainfall must be a random whole number of millimeters between 5 and 25 inclusive.

An incomplete Python program is provided below:

# Program to simulate a daily rainfall measurement

# TODO 1: Import the random library

# TODO 2: Create a constant called MIN_RAINFALL and set it to 5
MAX_RAINFALL = 25

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

# TODO 5: Display the message "Simulated daily rainfall: " followed
# by the value of simulated_rainfall

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

  • import the random library
  • create a constant called MIN_RAINFALL with the value 5
  • create a variable called simulated_rainfall
  • use a library call to generate a random number between MIN_RAINFALL and MAX_RAINFALL inclusive, assigning it to simulated_rainfall
  • display the string message "Simulated daily rainfall: " and the value of simulated_rainfall 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