Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ajfumero8 authored Jan 12, 2025
1 parent 8d22cdf commit ec8be68
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
47 changes: 47 additions & 0 deletions solutions/voting_age/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# **Challenge: Voting Age Checker**

## Description

This code should be able to state and verify a voter's age
And compare it to a set voting age
In order to return a value containing the voter's name and
if they are old enough to vote

Code should also ask for Input for the specific voter's name
Be able to return a correct value based on name

This code should use *min_age* and a defined *can_vote* functions
in order to state and verify ages of all the listed voters

It should also set the ages of the voters with their:

1. Name
2. Age

### Ex. Code

```python
min_age = 18

participants = {
'alice': {'age': 18},
'bob': {'age': 40},
'charlotte': {'age': 17},
}


# Write a function that would allow
# A Boolean output corresponding to their age
# And if the person can vote

```

### Testing

- Use ```print``` unit tests that set age and compare back to the minimum age
- Use unit tests that check for precise spelling and comparisons

### Helpful Links

- [Python Functions](https://www.w3schools.com/python/python_functions.asp)
- [How to Define and Call back to a function](https://www.geeksforgeeks.org/how-to-define-and-call-a-function-in-python/)
Empty file.
50 changes: 50 additions & 0 deletions solutions/voting_age/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Module for the Voting age challenge.
Contents:
- Contextual code for names and a list to refer back to
- Code that can refer back to minimum age and name list and produce an output base on name selection
Created on 2025-01-03
Author: Adolfo Fumero
"""

MIN_AGE = 18 # this states the minimum age for voting

participants = {
"Jackson": {"age": 18},
"Bob": {"age": 40},
"Charlotte": {"age": 17},
"Marley": {"age": 28},
"Erica": {"age": 6},
}


def check_voting_age(person):
"""
General:
This function's goal is to check the age of the participants
and if they are equal
or above the minimum voting age based on input of name
It pulls name and age from the Participants list and provides a Boolean output
Parameters:
Name: Correct name from Participants list
Name list: Jackson , Bob, Charlotte, Marley, Erica
Raises:
If an invalid name is written, it will provide a "Participant not found." Output
Correct capitalization is required, otherwise "Participant not found" Error will be raised
"""
return person["age"] >= MIN_AGE


# Ask for the name input
name = input("Enter the participant's name (Jackson, Bob, Charlotte, Marley, Erica): ")

# Check if the name exists in the participants dictionary
if name in participants:
result = check_voting_age(participants[name])
print(f"Can {name} vote?: {result}")
else:
print("Participant not found.")

0 comments on commit ec8be68

Please sign in to comment.