A program is being developed to show the daily rainfall measurements and calculate the total cost of buying promotional umbrellas. It displays each rainfall level stored in an array of measurements.
1: DISCOUNT_THRESHOLD = 80.00
2: daily_rainfall = [1.2, 0.5, 4.8, 0.0, 2.1]
3: total_cost = 0.0
4: print("Daily Rainfall Records:")
5: for rain in daily_rainfall:
6: print(str(rain) + " mm")
7: cost = float(input("Enter item cost (0 to stop): "))
8: while cost != 0.0:
9: total_cost = total_cost + cost
10: cost = float(input("Enter item cost (0 to stop): "))
11: if total_cost > DISCOUNT_THRESHOLD:
12: discount_rate = 0.15
13: else:
14: discount_rate = 0.05
15: final_total = total_cost * (1 - discount_rate)
16: print("Total price to pay: £" + str(final_total))
Identify the code features requested below from the program snippet shown above:
Name of a constant used in the program
Name of an array used in the program
Line number of an initialisation of a variable with a real number
Line numbers for a selection construct
Line numbers for a repetition construct (condition-controlled loop)
Line numbers for an iteration construct (count-controlled/collection loop)
Line number for an instruction that outputs information to the screen
50 exam-style questions on Edexcel GCSE Computer Science Constructs, covering Structural components of programs and Writing programs with control constructs. Each one has a worked solution and a mark scheme showing where the marks go.