Question 4
Edexcel Computer Science June 2022 Paper 2GCSE15 marks
On the specification
- 2.1 Binary6.1 Develop code6.2 Program constructs
Question text
4 A program converts a binary pattern to a positive denary integer. The user enters the binary pattern. The program loops continually until the user inputs an empty pattern to stop the program. A multiplier doubles for each position from right to left, to generate the place values for the binary pattern, i.e. 128, 64, 32, 16, 8, 4, 2, 1. When a 1 appears in the pattern, the place value is added to the running total. When a 0 appears in the pattern, nothing is added to the running total. The table shows accurate test results for three inputs. Input Output 1100 12 10101010 170 <empty> Exits program The lines of code in the program are mixed up. The indentation has been done for you. Open file Q04.py Amend the code to make the program work and produce the correct output. You will need to rearrange the lines. Do not change the functionality of the given lines of code. Do not add any additional functionality. Save your amended code as Q04FINISHED.py (Total for Question 4 = 15 marks)