Skip to content

Course home

Programming concepts

Programming concepts

EasyMediumHard
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
Question 50

An environmental scientist is collecting soil samples from a research site. They need to collect a total target mass of soil. Several individual samples will be gathered and weighed one by one, with each sample having a different mass.

Write a Python program that asks the scientist for the target mass of soil required, and then repeatedly asks for the mass of each collected sample until the target mass is met or exceeded.

The program should:

  • Prompt the user to enter the initial target mass of soil.
  • Prompt the user to enter the mass of an individual soil sample.
  • Subtract the sample mass from the remaining target mass:
    • If the remaining mass is more than 0, output the remaining mass still needed to reach the target, and repeat this process until the remaining target mass is 0 or less.
    • If the remaining mass is exactly 0, output the message Target reached exactly.
    • If the remaining mass is less than 0, output the message Excess is followed by the absolute difference (as a positive number) showing by how much the collected mass exceeded the target.

You should use indentation as appropriate, meaningful variable name(s), and Python syntax in your answer.

[8]
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