Skip to content

Instantly share code, notes, and snippets.

@martin-martin
Created August 27, 2020 10:39
Show Gist options
  • Save martin-martin/b27e8565b91d013df4811e7550b47a4f to your computer and use it in GitHub Desktop.
Save martin-martin/b27e8565b91d013df4811e7550b47a4f to your computer and use it in GitHub Desktop.

Let's look at a new scenario. In the following code snippet, you will create a conditional statement that will check your age and let you know how you can participate in elections depending on that factor:

>>> age = 10
>>> if age < 18:
...     print('You can follow the elections on the news')
... elif age < 35:
...     print('You can vote in all elections')
... elif age >= 35:
...     print('You can stand for any election')
... 
You can follow the elections on the news

In this example, you use if and elif. The keyword elif is short for "else if". So the code here is checking the age against different hard-coded values. If the age is less than 18, then the citizen can follow the elections on the news.

If they are older than 18 but less than 35, they can vote in all elections. Next you check if the citizen's age is greater than or equal to 35. Then they can run for any office themselves and participate in their democracy as a politician.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment