Skip to content

Instantly share code, notes, and snippets.

@Back2Basics
Created April 1, 2024 00:44
Show Gist options
  • Save Back2Basics/955949a1445ecbb98948bbadf29e7d51 to your computer and use it in GitHub Desktop.
Save Back2Basics/955949a1445ecbb98948bbadf29e7d51 to your computer and use it in GitHub Desktop.
# Hire person
# Hire other person
# print all employees
# fire person
# pay person (that wasn't fired)
# print all employees
def create_person(first_name: str, last_name: str, routing_number: int | None = None,
account_number: int | None = None):
return {
'first_name': first_name,
'last_name': last_name,
'routing_number': routing_number,
'account_number': account_number
}
def pay_person(person: dict, amount: int):
print(
f"{person['first_name']} {person['last_name']} was paid {amount} to account_number={person['account_number']} routing_number={person['routing_number']}.")
def hire_person(hr: dict, person: dict):
hr['employees'].append(person)
print(f"{person['first_name']} {person['last_name']} was hired.")
def fire_person(hr: dict, person: dict):
hr['employees'] = [p for p in hr['employees'] if p != person]
print(f"{person['first_name']} {person['last_name']} was fired.")
def print_all_employees(hr: dict):
for person in hr['employees']:
print(f"{person['first_name']} {person['last_name']}: {person['account_number']} {person['routing_number']}")
hr = {'employees': []}
arial = create_person("Arial", "Greentext")
hire_person(hr, arial)
arial['account_number'] = "123456789"
arial['routing_number'] = "987654321"
felix = create_person("Felix", "Furlough")
hire_person(hr, felix)
print_all_employees(hr)
pay_person(arial, 1000)
fire_person(hr, felix)
print_all_employees(hr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment