-
تعریف این کلاس را کامل کن.
'' Employee: def __init__(self, name, position, department): self.name = name self.position = position self.department = department
-
شی جدیدی با نام employee_1 از کلاس Employee بساز.
class Employee: def __init__(self, name, position, department, salary): self.name = name self.position = position self.department = department self.salary = salary employee_1 = ''("Sarah Anderson", "Senior Python Engineer", "Engineering", 5000)
-
نامی که در شی employee_1 قرار گرفته است را چاپ کن.
class Employee: def __init__(self, name, position, department, salary): self.name = name self.position = position self.department = department self.salary = salary employee_1 = Employee("Sarah Anderson", "Senior Python Engineer", "Engineering", 5000) print('')
-
شی employee_3 را به لیست اضافه کن.
class Employee: def __init__(self, name, position, department, salary): self.name = name self.position = position self.department = department self.salary = salary employee_1 = Employee("Sarah Anderson", "Senior Python Engineer", "Engineering", 5000) employee_2 = Employee("Alice Smith", "Junior Data Analyst", "Analytics", 3500) employee_3 = Employee("Bob Johnson", "Product Manager", "Product Management", 6000) employee_list = [employee_1, employee_2, '']
-
خروجی این برنامه چیست؟
class Employee: def __init__(self, name, position, department, salary): self.name = name self.position = position self.department = department self.salary = salary employee_1 = Employee("Sarah Anderson", "Senior Python Engineer", "Engineering", 5000) employee_2 = Employee("Alice Smith", "Junior Data Analyst", "Analytics", 3500) employee_3 = Employee("Bob Johnson", "Product Manager", "Product Management", 6000) employee_list = [employee_1, employee_2, employee_3] for employee in employee_list: print(employee.name)
-
فانکشن print_employee_info را صدا بزن.
class Employee: def __init__(self, name, position, department, salary): self.name = name self.position = position self.department = department self.salary = salary def print_employee_info(self): print('Employee info > Name:', self.name, 'Position:', self.position, 'Department:', self.department, 'Salary:', self.salary) employee_1 = Employee("Sarah Anderson", "Senior Python Engineer", "Engineering", 5000) employee_2 = Employee("Alice Smith", "Junior Data Analyst", "Analytics", 3500) employee_3 = Employee("Bob Johnson", "Product Manager", "Product Management", 6000) employee_list = [employee_1, employee_2, employee_3] for employee in employee_list: '' ''' Employee info > Name: Sarah Anderson Position: Senior Python Engineer Department: Engineering Salary: 5000 Employee info > Name: Alice Smith Position: Junior Data Analyst Department: Analytics Salary: 3500 Employee info > Name: Bob Johnson Position: Product Manager Department: Product Management Salary: 6000 '''
تمرین کلاس ها در پایتون
توسط
دیدگاهتان را بنویسید