-1

i print my student info i get that but i get a none after that i dont understand why? and i tried return but it only does it for the first value in "def get_info". Output: 10 saif 14 5 None ahmed 48 20 None

class Student:
    def __init__(self, name, age, yearsplay):
        self.name = name
        self.age = age
        self.yearsplay = yearsplay

    def get_info(self):
        print(self.name) 
        print( self.age)
        print(self.yearsplay) 

class Course:
    def __init__(self, Maxstudents):
        self.Maxstudents = Maxstudents
        self.Students = []

        print(Maxstudents)

    def add_students(self, Student):
        if len(self.Students) < self.Maxstudents:
            self.Students.append(Student)
            print(Student.get_info())



s1 = Student("saif", 14, 5)
s2 = Student("ahmed", 48, 20)
c = Course(10)
c.add_students(s1)
c.add_students(s2)
Saif1708
  • 3
  • 1
  • 2
    What does get_info return in your opinion? – DownloadPizza Jan 29 '22 at 12:44
  • Does this answer your question? [Why is this printing 'None' in the output?](https://stackoverflow.com/questions/28812851/why-is-this-printing-none-in-the-output) – DownloadPizza Jan 29 '22 at 12:47
  • As you can see this is a duplicate of a duplicate. Maybe try searching here next time first – DownloadPizza Jan 29 '22 at 12:48
  • Does this answer your question? [Why is the output of my function printing out "None"?](https://stackoverflow.com/questions/7053652/why-is-the-output-of-my-function-printing-out-none) – Matthias Jan 29 '22 at 14:13

1 Answers1

0

In this line, print(Student.get_info()) calls get_info, and it returns None. So, None will be printed.

Happy Ahmad
  • 1,072
  • 2
  • 14
  • 33