Advertisement
Kulas_Code20

Python_List

Nov 22nd, 2022 (edited)
805
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.95 KB | None | 0 0
  1. from os import system
  2. # Declaring variables
  3. names: list = []
  4. position: list = []
  5. gender: list = []
  6. salary: list = []
  7. contact_number: list = []
  8. idCount: list = []
  9.  
  10.  
  11. def add() -> None:
  12.     toplabel("ADD RECORD")
  13.     names.append(input("Enter your name: "))
  14.     position.append(input("Enter your position: "))
  15.     gender.append(input("Enter your gender: "))
  16.     salary.append(float(input("Enter your salary: ")))
  17.     contact_number.append(input("Enter your phone number: "))
  18.  
  19.     input("\nPress any key to continue")
  20.     return None
  21.  
  22.  
  23. def edit() -> None:
  24.     system("cls")
  25.     toplabel("EDIT RECORD")
  26.     idCount: list = []
  27.     if len(names) > 0:
  28.         for i in range(len(names)):
  29.             print(f"{i} | {names[i]} | {position[i]} | {gender[i]} | {salary[i]:.2f} | {contact_number[i]}")
  30.             idCount.append(i)
  31.     else:
  32.         print("Empty list!")
  33.     idnum: int = int(input("Select record id: "))
  34.     if len(idCount) > 0:
  35.         for index in idCount:
  36.             if idnum == index:
  37.                 print("Employee Found")
  38.                 print("----------------------------------------------------")
  39.                 # Input to update data in specific index
  40.                 names[idnum] = input("Enter your name: ")
  41.                 position[idnum] = input("Enter your position: ")
  42.                 gender[idnum] = input("Enter your gender: ")
  43.                 salary[idnum] = float(input("Enter your salary: "))
  44.                 contact_number[idnum] = input("Enter your phone number: ")
  45.     else:
  46.         print("Employee Not Found!")
  47.  
  48.     input("\nPress any key to continue")
  49.     return None
  50.  
  51.  
  52. def delete() -> None:
  53.     toplabel("DELETE RECORD")
  54.     idCount: list = []
  55.     if len(names) > 0:
  56.         for i in range(len(names)):
  57.             print(f"{i} | {names[i]} | {position[i]} | {gender[i]} | {salary[i]:.2f} | {contact_number[i]}")
  58.             idCount.append(i)
  59.     else:
  60.         print("Empty list!")
  61.     idnum: int = int(input("Select record id: "))
  62.     if len(idCount) > 0:
  63.         for index in idCount:
  64.             if idnum == index:
  65.                 print("Employee Found")
  66.                 print("----------------------------------------------------")
  67.                 ans: str = input("Do you want to delete this employee?(y/n: ")
  68.                 if ans.lower() == 'y':
  69.                     names.pop(idnum)
  70.                     position.pop(idnum)
  71.                     gender.pop(idnum)
  72.                     salary.pop(idnum)
  73.                     contact_number.pop(idnum)
  74.                     print("Employee Deleted!")
  75.     else:
  76.         print("Employee Not Found!")
  77.  
  78.     input("\nPress any key to continue")
  79.     return None
  80.  
  81.  
  82. def viewdata() -> None:
  83.     toplabel("VIEW RECORDS")
  84.     if len(names) > 0:
  85.         for i in range(len(names)):
  86.             print(f"{i} | {names[i]} | {position[i]} | {gender[i]} | {salary[i]:.2f} | {contact_number[i]}")
  87.     else:
  88.         print("Empty list!")
  89.     input("\nPress any key to continue")
  90.     return None
  91.  
  92.  
  93. def exit() -> None:
  94.     system("cls")
  95.     print("Thank you!")
  96.     quit()
  97.     return None
  98.  
  99.  
  100. def toplabel(title: str) -> None:
  101.     system("cls")
  102.     print(f"------------ {title} ------------")
  103.     return None
  104.  
  105.  
  106. def displayMenu() -> None:
  107.     system("cls")
  108.     menuitem = [
  109.         "------------ Main Menu ------------",
  110.         "a. ADD RECORD",
  111.         "b. EDIT RECORD",
  112.         "c. DELETE RECORD",
  113.         "d. VIEW RECORD",
  114.         "e. EXIT"
  115.     ]
  116.     # Display using list comprehension
  117.     [print(item) for item in menuitem]
  118.     return None
  119.  
  120.  
  121. def main() -> None:
  122.     select: str = ""
  123.     while select != 'e':
  124.         displayMenu()
  125.         select = input("Enter option(a-e): ")
  126.         if select == 'a':
  127.             add()
  128.         elif select == 'b':
  129.             edit()
  130.         elif select == 'c':
  131.             delete()
  132.         elif select == 'd':
  133.             viewdata()
  134.         elif select == 'e':
  135.             exit()
  136.  
  137. if __name__ == "__main__":
  138.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement