Skip to content

Course home

Programming concepts

Programming concepts

EasyMediumHard
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
Question 35

Question 16 is about a darts game played against a computer.

The aim of the game is to get as close to a target score of 50 as possible, without going over 50. If your score goes over 50, you lose.

The player's score starts at 0.

For each turn:

  • two virtual darts (each scoring a value from 1 to 20 inclusive) are thrown
  • the total of the two dart throws is added to the player's total score
  • the value of each dart throw and the player's updated total score are output
  • if the current score is less than 50, the player is asked if they would like to throw again. If the player inputs "yes", they get another turn; otherwise, the game ends.

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

  • if the final score is exactly 50, output a message to say the player has won
  • if the final score is greater than 50, output a message to say the player has lost
  • if the final score is less than 50, the program generates a random integer between 35 and 50 inclusive representing the computer's score:
    • if this computer score is greater than the player's final score, output a message to say the player has lost
    • otherwise, output a message to say the player has won.

Write a Python program to simulate this game.

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

import random

The dart throws 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

Dart 1: 12
Dart 2: 8
Current score: 20
Throw again? yes

Dart 1: 15
Dart 2: 10
Current score: 45
Throw again? yes

Dart 1: 5
Dart 2: 4
Current score: 54
Bust! 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