mercredi 27 mai 2020

How to call classes and function in if statement in python 3X

I created a simple menu that should call classes and function from If statement. it just prints "A" every time I run the code. I'm new in python OOP. I also tried some codes from here. What is the problem with my code?

class CustomError(Exception):
pass

class employee:
    def menu(self):


        print('\tA = To Add Employee Record')
        print('\tB = To Update Employee Record')
        print('\tC = To Increase Employee Salary')
        print('\tD = To Generate Payslip')
        print('\tX = Exit')
        choice = input("\nType here! ").upper()
    def exec_menu(self):
        choice ="A"
        while True:
            if choice == "A":
                rec = add_record  #this is from another class
                rec.employee_info()
            elif choice =="B":
                pass
            elif choice == "C":
                pass
            elif choice == "D":
                pass
            elif choice =="X":
                exit()
            else:
                print("Whong value the system will now exit!")
                exit()


class add_record:

    def employee_info(self):
        print("Employee number must be 9 numbers long")
        print("Name and Lastname must be charcters only")
        print("Plese choose on this Department name: Accounting, Human Resources,  Marketing,  Finance,  MIS,  Admin")
        while True:
            print("*" * 70)
            Employee_empno = int(input("Enter Unique number for your Employee Number:"))
            Employee_last = str(input("Enter Lastname:"))
            Employee_first = str(input("Enter Firstname:"))
            Employee_dept = input("Enter Department:").upper()
            Employee_rate = int(input("Enter Rate per hour:"))

            with open('empRecord.txt', 'a') as f:
                f.write(f"\n{Employee_empno}, {Employee_last}, {Employee_first}, {Employee_dept}, {Employee_rate};")
            print("if you want add more Employee in Information press 1 ")
            user_input = input("Enter:")
        if user_input != "1":


records = add_record()
employee.menu(any)

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire