Question 4

Edexcel Computer Science June 2023 Paper 2GCSE15 marks

On the specification

6.3 Data types and structures6.4 Input and output6.5 Operators
Question text

4 A program is required to calculate the volume of a prism. All dimensions are entered by the user. The dimensions are decimal numbers greater than 0 The volume of this prism is the area of the triangle multiplied by the length of the prism. h l b The formula to calculate the area of the triangle is: 1 A  bh 2 • A is the area of the triangle • b is the width of the base of the triangle • h is the height of the triangle The formula to calculate the volume of this prism is: V  Al • V is the volume of the prism • A is the area of the triangle • l is the length of the prism The program must meet these requirements: • take three decimal inputs from the user – all inputs must be greater than zero • check for invalid inputs, using relational and logical operators • display an error message if an input is invalid. Invalid input should not be processed • process all valid inputs • calculate the area of the triangle • display the area of the triangle, rounded to two decimal places • calculate the volume of the prism • display the volume of the prism using the <string>.format() function in eight columns with two decimal places. Include the words ‘cubic units’ after the volume • in all cases, display a goodbye message just before terminating. Test the functionality of the program using the data in this table. b h l A V Prism 1 4.567 1.23 89.01 2.81 250.00 Prism 2 2.74 6.01 5.55 8.23 45.70 Open file Q04.py Amend the code to meet the requirements. Do not add any additional functionality. Save your amended code as Q04FINISHED.py (Total for Question 4 = 15 marks)