Answer to Question #324089 in Python for Eren

Question #324089

Employee Record is composed of the following:

  • record_no
  • first_name
  • last_name
  • address
  • city
  • county
  • state
  • bdate
  • zip
  • phone1
  • phone2
  • email
  • web


In the given string, Each employee data is separated by comma (,). Each record is separated by semicolon (;).


A - The program must be able to display employee record based on the given key.

B - The program must be able to display the last name, first name and age of an

employee based on the given key. (assume that the current date is April 22, 2022)

C - The program must be able to display the number of employee in a given county.

D - The program must be able to count no. of employee based on a given email provider site.




1. data

Output


Enter·your·choice·(A/B/C/D/X-exit):·A
Enter·Record·No.:·10

First·Name:·Kris
Last·name:·Marrier
Address:·228·Runamuck·Pl·#2808
City:·Baltimore
County:·Baltimore·City
State:·MD
Birth·Date:·12/19/1983
zip:·21224
phone1:·410-655-8723
phone2:·410-804-4694
Email:·kris@gmail.com
web:·http://www.kingchristopheraesq.com

Enter·your·choice·(A/B/C/D/E/X-exit):·X
Bye!






1
Expert's answer
2022-04-06T13:55:22-0400
from datetime import date, datetime


PATH_TO_DATA = r".\data_test.csv"

def get_age(birthday: str):
    today = date.today()
    birthday = datetime.strptime(birthday, '%d.%m.%Y').date()
    age = today.year - birthday.year
    if today.month < birthday.month:
        age -= 1
    elif today.month == birthday.month and today.day < birthday.day:
        age -= 1
    return age


with open(PATH_TO_DATA, 'r') as data:
        data = [i.split(",") for i in data.read().split(";") if len(i) > 1]
        employee_records = {}
        for i in data:
            
            employee_records[i[0]] = {
                "first_name": i[1],
                "last_name": i[2],
                "address": i[3],
                "city": i[4],
                "county": i[5],
                "state": i[6],
                "bdate": i[7],
                "age": get_age(i[7]),
                "zip": i[8],
                "phone1": i[9],
                "phone2": i[10],
                "email": i[11],
                "web": i[12],
            }


class EmployeeRecordsProgramm():
    def __init__(self, employee_records) -> None:
        self.employee_records = employee_records
        self.user_choise()

    def user_choise(self):
        options = input("Enter your choice (A/B/C/D/X-exit): ")
        if options == "A":
            self.choice_A()
        if options == "B":
            self.choice_B()
        if options == "C":
            self.choice_C()
        if options == "D":
            self.choice_D()
        if options == "X":
            self.choice_X()

    def choice_A(self):
        record_no = input("Enter Record No: ")
        print("  ")
        print(f"First Name: {employee_records[record_no]['first_name']}")
        print(f"Last name: {employee_records[record_no]['last_name']}")
        print(f"Address: {employee_records[record_no]['address']}")
        print(f"City: {employee_records[record_no]['city']}")
        print(f"County: {employee_records[record_no]['county']}")
        print(f"State: {employee_records[record_no]['state']}")
        print(f"Birth Date: {employee_records[record_no]['bdate']}")
        print(f"zip: {employee_records[record_no]['zip']}")
        print(f"phone1: {employee_records[record_no]['phone1']}")
        print(f"phone2: {employee_records[record_no]['phone2']}")
        print(f"Email: {employee_records[record_no]['email']}")
        print(f"web: {employee_records[record_no]['web']}")
        print("  ")


    def choice_B(self):
        record_no = input("Enter Record No: ")
        print("  ")
        print(f"First Name: {employee_records[record_no]['first_name']}")
        print(f"Last name: {employee_records[record_no]['last_name']}")
        print(f"Age: {employee_records[record_no]['age']}")
        print("  ")

    def choice_C(self):
        count = 0
        county = input("Enter county: ")
        for record_no in self.employee_records:
            if employee_records[record_no]['county'] == county:
                count += 1
        print("  ")
        print(f"In {county} {count} employeers")
        print("  ")

    def choice_D(self):
        count = 0
        email_provider_site = input("Input email provider site: ")
        for record_no in self.employee_records:
            if employee_records[record_no]['email'].endswith(email_provider_site):
                count += 1
        print("  ")
        print(f"In {email_provider_site} {count} employeers")
        print("  ")

    def choice_X(self):
        print("  ")
        print("Bye!")
        exit(0)


while True:
    EmployeeRecordsProgramm(employee_records)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS