+ 1

Python, whats wrong?

class students: def __init__(self,name,age,grade): self.name=name self.age=age self.grade=grade def introduce(self): print(self.name,self.age,self.grade) def met(self): return self.grade while True: st=students(input(),int(input()),int(input())) if self.name== 'stop': break else: if gr>=15: st.introduce()

2nd May 2020, 10:18 PM
Κωνσταντίνος Αλεξανδρίδης
9 Respuestas
+ 1
Thanks a lot
2nd May 2020, 10:55 PM
Κωνσταντίνος Αλεξανδρίδης
+ 1
Then if you really wanted to throw the method in a while loop so itll just make students forever or whenever you tell it to stop
2nd May 2020, 10:55 PM
Slick
Slick - avatar
0
Its looking good until the while loop and 'students' should be 'Student' to help with reading. If you'd like to print out their info, take the while loop out first, then something like student = [] s1 = students('Billy',14,8) s2 = students('Sam',12,7) s3 = students('Tommy',11,6) student.append(s1) student.append(s2) student.append(s3) for s in student: s.introduce()
2nd May 2020, 10:31 PM
Slick
Slick - avatar
0
How can i take only the name of a student to compare it
2nd May 2020, 10:37 PM
Κωνσταντίνος Αλεξανδρίδης
0
You see how I made variables for each students object? s1, s2, and s3? Call s1.introduce() or s3.introduce() to have them do it seperately
2nd May 2020, 10:39 PM
Slick
Slick - avatar
0
Im trying to make a programm that you create objects until you insert the word stop as the New students name
2nd May 2020, 10:41 PM
Κωνσταντίνος Αλεξανδρίδης
0
Im newbie
2nd May 2020, 10:41 PM
Κωνσταντίνος Αλεξανδρίδης
0
No worries, the only problem with that, that i see, is that your input are different kinds of values. You have one string and two integers for each instance of the class. Say that didnt matter, then what youd try creating a method called "add_student" the method should take all the input to instantiate a student object (name, grade, and age) then it should take that info and create a new student object with it.
2nd May 2020, 10:52 PM
Slick
Slick - avatar
0
class student: def __init__(self ,name ,age ,university name,rating): self.name=name self.age=age self.universityname=universityname self.rating=rating def is_excellent(self): if self.rating>=4: return True else: return False
18th Feb 2022, 3:47 PM
Omar Azab
Omar Azab - avatar