Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from os import system
- # Declaring variables
- names: list = []
- position: list = []
- gender: list = []
- salary: list = []
- contact_number: list = []
- idCount: list = []
- def add() -> None:
- toplabel("ADD RECORD")
- names.append(input("Enter your name: "))
- position.append(input("Enter your position: "))
- gender.append(input("Enter your gender: "))
- salary.append(float(input("Enter your salary: ")))
- contact_number.append(input("Enter your phone number: "))
- input("\nPress any key to continue")
- return None
- def edit() -> None:
- system("cls")
- toplabel("EDIT RECORD")
- idCount: list = []
- if len(names) > 0:
- for i in range(len(names)):
- print(f"{i} | {names[i]} | {position[i]} | {gender[i]} | {salary[i]:.2f} | {contact_number[i]}")
- idCount.append(i)
- else:
- print("Empty list!")
- idnum: int = int(input("Select record id: "))
- if len(idCount) > 0:
- for index in idCount:
- if idnum == index:
- print("Employee Found")
- print("----------------------------------------------------")
- # Input to update data in specific index
- names[idnum] = input("Enter your name: ")
- position[idnum] = input("Enter your position: ")
- gender[idnum] = input("Enter your gender: ")
- salary[idnum] = float(input("Enter your salary: "))
- contact_number[idnum] = input("Enter your phone number: ")
- else:
- print("Employee Not Found!")
- input("\nPress any key to continue")
- return None
- def delete() -> None:
- toplabel("DELETE RECORD")
- idCount: list = []
- if len(names) > 0:
- for i in range(len(names)):
- print(f"{i} | {names[i]} | {position[i]} | {gender[i]} | {salary[i]:.2f} | {contact_number[i]}")
- idCount.append(i)
- else:
- print("Empty list!")
- idnum: int = int(input("Select record id: "))
- if len(idCount) > 0:
- for index in idCount:
- if idnum == index:
- print("Employee Found")
- print("----------------------------------------------------")
- ans: str = input("Do you want to delete this employee?(y/n: ")
- if ans.lower() == 'y':
- names.pop(idnum)
- position.pop(idnum)
- gender.pop(idnum)
- salary.pop(idnum)
- contact_number.pop(idnum)
- print("Employee Deleted!")
- else:
- print("Employee Not Found!")
- input("\nPress any key to continue")
- return None
- def viewdata() -> None:
- toplabel("VIEW RECORDS")
- if len(names) > 0:
- for i in range(len(names)):
- print(f"{i} | {names[i]} | {position[i]} | {gender[i]} | {salary[i]:.2f} | {contact_number[i]}")
- else:
- print("Empty list!")
- input("\nPress any key to continue")
- return None
- def exit() -> None:
- system("cls")
- print("Thank you!")
- quit()
- return None
- def toplabel(title: str) -> None:
- system("cls")
- print(f"------------ {title} ------------")
- return None
- def displayMenu() -> None:
- system("cls")
- menuitem = [
- "------------ Main Menu ------------",
- "a. ADD RECORD",
- "b. EDIT RECORD",
- "c. DELETE RECORD",
- "d. VIEW RECORD",
- "e. EXIT"
- ]
- # Display using list comprehension
- [print(item) for item in menuitem]
- return None
- def main() -> None:
- select: str = ""
- while select != 'e':
- displayMenu()
- select = input("Enter option(a-e): ")
- if select == 'a':
- add()
- elif select == 'b':
- edit()
- elif select == 'c':
- delete()
- elif select == 'd':
- viewdata()
- elif select == 'e':
- exit()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement