Voting Age Checker – Flowchart

For this challenge you are going to code a script to ask a user how old they are and inform them as to whether they are old enough to vote or not. If they are not old enough to vote, the script will calculate how many years the user will have to wait before being allowed to vote.

Flowchart


flowchart-voting-age-checker

Task #1


Recreate this flowchart by writing the pseudo-code of this algorithm using code2flow.com.

Task #2


Implement this code using Python.

Task #3


Test your code. Is it behaving the way you would expect? What input data could you use to test your code?

Test # Input Values Expected Output Actual Output
#1 Age: 21 You can vote
#2 Age: 16 You will be able to vote in 2 years.
#3 Age: 100 You can vote.
#4 Age: 0 You will be able to vote in 18 years.
#5 Age: 18 You can vote
#6 Age: (leave blank) Error Message
#7 Age: “I am fifteen years old” Error Message

Task #4: Improve your code


How could you improve your code to fix some of the errors you have spotted by completing your test plan? What validation routines could you add to this code to make it more robust?

Share Button
Posted in Computer Science, Computing Concepts, Python - Beginner, Python Challenges Tagged with: ,

Our Latest Book