Skip to content

Course home

Structured programming and subroutines (procedures and functions)

Structured programming and subroutines (procedures and functions)

EasyMediumHard
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
Question 53

Write a subroutine in Python called checkTreasure that will count the number of times the string "Gold" appears on an adventure map.

The subroutine should:

  • take a 2D array called islandMap as a parameter
  • count the number of times "Gold" appears in the islandMap array
  • output the word "Jackpot" if there are exactly five "Gold" items in the array
  • output the total number of "Gold" items if there are fewer than five.

You must write your own counting routine utilizing nested loops and not use any built-in count functions or methods (such as .count()) that might be available in Python.

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

Figure 1

012
0SandGoldSand
1GoldForestGold
2CastleGoldGold
[8]
Markscheme

Structured programming and subroutines (procedures and functions) Questions

  1. GCSE
  2. /Computer Science
  3. /Structured programming and subroutines (procedures and functions)

131 exam-style questions on AQA GCSE Computer Science Structured programming and subroutines (procedures and functions). Each one has a worked solution and a mark scheme showing where the marks go.

Question bank