An incomplete Python program for simulating a chemical reactor's target temperature is shown in Figure 1 below.
The program should generate a random target temperature between 180 and 360 degrees Celsius (including 180 and 360). This will be the secret target temperature the user has to guess.
Figure 1
1 import random
2
3 print("Enter your guess for the target temperature (C)")
4 userTemp = int(input())
5 while userTemp < 180 or userTemp > 360:
6 print("Invalid temperature")
7 userTemp = int(input())
8 print("Valid temperature entered")
9 if targetTemp == userTemp:
10 print("Warning: Reactor core matches critical threshold!")
Write the Python code that should be used on line 2 in Figure 1 to:
You must use random.randrange(a, b) in your Python code.
Note that random.randrange(a, b) generates a random integer in the range a a\,a to bbb, starting at a a\,a but finishing one before bbb (exclusive of bbb).
8 exam-style questions on AQA GCSE Computer Science Random number generation in a programming language. Each one has a worked solution and a mark scheme showing where the marks go.