Question 3
Edexcel Computer Science June 2024 Paper 2GCSE10 marks
On the specification
- 6.3 Data types and structures6.4 Input and output6.5 Operators
Question text
3 A program is required to calculate the total cost of items purchased. Items are sold by count or by weight. The user enters the number 1 if the purchase is by count or the number 5 if the purchase is by weight of items. The user then enters either the count or the weight in kilograms. The program checks for invalid input. If the input is valid, the program calculates and displays the total cost. Currency formatting with two decimal places and a symbol is not required. The table shows test results. Purchase Count of Weight in Output category items kilograms 13 Total cost is 3.69 10 Invalid number of items 54.5 Total cost is 15.525 5 −6.6 Invalid weight 3 Invalid purchase type Open file Q03.py Amend the code to: • create an integer variable named purchaseType and set it to 0 • complete a line with the correct logical operator and the correct constant • complete a line with the correct constant • complete a line to accept a real value for the weight in kilograms • complete a line to calculate the total cost based on weight • complete a line to check for a 0 or negative count of items • complete a line with the correct relational operator • add a line to display an informative message and the total cost. Do not add any additional functionality. Save your amended code as Q03FINISHED.py (Total for Question 3 = 10 marks)