Photo AI

OCR town are holding an election with three candidates (A, B and C) - OCR - GCSE Computer Science - Question 8 - 2018 - Paper 1

Question icon

Question 8

OCR-town-are-holding-an-election-with-three-candidates-(A,-B-and-C)-OCR-GCSE Computer Science-Question 8-2018-Paper 1.png

OCR town are holding an election with three candidates (A, B and C). An electronic voting booth will be used to allow people to vote. Write an algorithm that: - Al... show full transcript

Worked Solution & Example Answer:OCR town are holding an election with three candidates (A, B and C) - OCR - GCSE Computer Science - Question 8 - 2018 - Paper 1

Step 1

Initialisation of A, B and C as zero

96%

114 rated

Answer

  1. Initialize variables:
    countA = 0
    countB = 0
    countC = 0
    totalVotes = 0
    

Step 2

Allows input of anything from the user

99%

104 rated

Answer

  1. Create a loop that will continue until "END" is entered:
    while True:
        vote = input('Enter A, B or C (or type "END"): ')
    

Step 3

Incrementing A, B and C depending on input

96%

101 rated

Answer

  1. Process the input and update the vote counts:
        if vote == 'A':
            countA += 1
            totalVotes += 1
        elif vote == 'B':
            countB += 1
            totalVotes += 1
        elif vote == 'C':
            countC += 1
            totalVotes += 1
        elif vote == 'END':
            break
        else:
            print('Invalid input, please enter A, B or C')
    

Step 4

At any point allows the official to type in 'END'

98%

120 rated

Answer

  1. Print the results when 'END' is entered:
    print(f'A: {countA}, B: {countB}, C: {countC}, Total Votes: {totalVotes}')
    

Join the GCSE students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

Other GCSE Computer Science topics to explore

;