7Medium
0/7

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]

Data types and structures Questions

Practise Edexcel GCSE Computer Science Data types and structures with exam-style questions for GCSE Computer Science. 45 questions covering Primitive and structured data types, Using variables and constants, and Manipulating strings, 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

Data types and structures Questions

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