Skip to content

Course home

Programming concepts

Programming concepts

EasyMediumHard
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
Question 28

An astronaut is controlling a deep-space mining drone to harvest helium-3 fuel cells from an asteroid field.

The aim of the mission is to harvest as close to a target of 80 units of fuel as possible, without going over 80. If the total harvest goes over 80, the fuel tank overloads and the player loses.

The drone's harvested fuel starts at 0.

For each mining turn:

  • two automated drills (each harvesting a random integer value from 5 to 30 units inclusive) are deployed
  • the total of the two drill harvests is added to the drone's running fuel total
  • the fuel harvested by each drill and the updated running fuel total are output
  • if the current total is less than 80, the player is asked if they would like to mine again. If the player inputs "yes", they get another mining turn; otherwise, the mining session ends.

At the end of the session, the program should run as follows:

  • if the final fuel total is exactly 80, output a message to say the player has achieved a perfect harvest and won
  • if the final fuel total is greater than 80, output a message to say the tank has overloaded and the player has lost
  • if the final fuel total is less than 80, the program simulates an AI competitor's final harvest by generating a random integer between 60 and 80 inclusive:
    • if this competitor score is greater than the player's final harvest, output a message to say the competitor wins and the player has lost
    • otherwise, output a message to say the player has won.

Write a Python program to simulate this deep-space harvesting game.

The first line of the program must import the random library:

import random

The drill harvests must be generated using random.randint(a, b) which returns a random integer in the range a to b inclusive.

You should use meaningful variable names and correct Python syntax in your answer.

Example Output

Drill 1: 18
Drill 2: 25
Current harvest: 43
Mine again? yes

Drill 1: 12
Drill 2: 15
Current harvest: 70
Mine again? yes

Drill 1: 8
Drill 2: 9
Current harvest: 87
Overloaded! You lose.
[11]
Markscheme

Programming concepts Questions

  1. GCSE
  2. /Computer Science
  3. /Programming concepts

298 exam-style questions on AQA GCSE Computer Science Programming concepts. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank