- 1

write a code with class in python

i have some problems with writing following program by python: Write a program to design a class that has the following information 1.Master's number 2.Teacher's name and surname 3.teaching The amount paid per hour Then, using this, write a program to provide the list of teacher with their salaries. Then teachers should be presented who have the same salary, and if their salaries are not the same, they should be leveled or grouped here is my code: class user: a=[] b=[] def __init__(self,teachername="undefiend",teacherfamily="undefiend",teachersalary=0): self.un1=teachername self.uf1=teacherfamily self.ua1=teachersalary def showinfo(self) : return f" {self.un1}{self.uf1}{self.ua1 }" #============================================================================== def salarycomp2(self,teachername): if self.ua1<15000: user.a.append(teachername) else : user.b.append(teachername) #================================================================================ def salarycomp(self,other) : if self.ua1==other.ua1: print("yes") else: user.salarycomp2() tt=user("sara","alae",30000) hhh=user("jack","parkor",300000) gg=user("mikel","ebel",20000) ff=user("daya","eskafi",10000) print(tt.showinfo()) print(hhh.showinfo()) print(gg.showinfo()) print(ff.showinfo()) user.salarycomp() errors: Traceback (most recent call last): File "c:\Users\SONY\Desktop\New folder\first.py", line 36, in <module> user.salarycomp() TypeError: salarycomp() missing 2 required positional arguments: 'self' and 'other'

11th Oct 2022, 6:43 AM
sara
4 Answers
+ 3
1. Variable names such as ua1, un1, tt, hhh, and the like are the worst you can choose 2. Why do you have two methods by the same name that do different things? From the very start become accustomed to using descriptive names! 3. salarycomp is defined as instance method, but you are calling it on the class. That is the error you are getting. Also, the method requires an argument 'other', a user object to compare to.
11th Oct 2022, 7:13 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 2
sara Pls add a link to your code in Code Playground to the question description. It allows us to see the code clearly and test it.
11th Oct 2022, 9:32 AM
Emerson Prado
Emerson Prado - avatar
0
i edited my code but now it does not know( ua1 )in (other.ua1) and when i want to give (other) as a argument to salarycomp() it does not accept. here is link : https://www.sololearn.com/compiler-playground/c85F3xABLO34
11th Oct 2022, 7:39 PM
sara
0
Ah, links don't work this way. Do like this: 1. Edit your question 2. Go to the question description 3. Tap "+" button 4. Tap "Code" 5. Choose the code in question
12th Oct 2022, 1:42 AM
Emerson Prado
Emerson Prado - avatar