OCR town are holding an election with three candidates (A, B and C) - OCR - GCSE Computer Science - Question 8 - 2018 - Paper 1
Question 8
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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Set countA = 0, countB = 0, countC = 0
Set totalVotes = 0
Step 2
Allows input of (anything) from the user
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Print("Total votes for A: ", countA)
Print("Total votes for B: ", countB)
Print("Total votes for C: ", countC)
Print("Total votes overall: ", totalVotes)