Skip to content

Course home

Sign up

Data types and structures

EasyMedium
12345678910
Question 1

A program is being written to simulate the environmental conditions of a smart greenhouse. The simulator needs to generate a random humidity percentage as a whole number between 45 and 85 inclusive.

An incomplete Python program is provided below:

# Program to simulate greenhouse humidity levels

# TODO 1: Import the random library

# TODO 2: Create a constant called MAX_HUMIDITY and set it to 85
MIN_HUMIDITY = 45

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

# TODO 5: Display the message "Current relative humidity: " followed
# by the value of simulated_humidity

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

  • import the random library
  • create a constant called MAX_HUMIDITY with the value 85
  • create a variable called simulated_humidity
  • use a library call to generate a random number between MIN_HUMIDITY and MAX_HUMIDITY inclusive, assigning it to simulated_humidity
  • display the string message "Current relative humidity: " and the value of simulated_humidity on the screen

Do not add any additional functionality.

[7]
Markscheme

Data types and structures Questions

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

44 exam-style questions on Edexcel GCSE Computer Science Data types and structures, covering Primitive and structured data types, Using variables and constants, and Manipulating strings. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank