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

Set countA = 0, countB = 0, countC = 0 Set totalVotes = 0

Step 2

Allows input of (anything) from the user

99%

104 rated

Answer

While true: vote = input("Enter A, B or C (or type 'END' to finish): ")

Step 3

Incrementing A, B and C depending on input

96%

101 rated

Answer

If vote == "A": countA += 1 totalVotes += 1 Else if vote == "B": countB += 1 totalVotes += 1 Else if vote == "C": countC += 1 totalVotes += 1 Else if vote == "END": break

Step 4

Prints out 3 individual counts and prints calculated total count

98%

120 rated

Answer

Print("Total votes for A: ", countA) Print("Total votes for B: ", countB) Print("Total votes for C: ", countC) Print("Total votes overall: ", 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

;