Q:

python oop tutorial

# Object Oriented programing
# for begginer in python 3
# and advanced in python 

class Student():
    def __init__(self, name, age, grade):
        self.name = name
        self.age = age
        self.grade = grade # 0- 100

    def get_grade(self):
        return self.grade


class Coures:
    def __init__(self, name, max_students):
        self.name = name
        self.max_students = max_students
        self.students = []

        def add_student(self, student):
            if len(self.students) < self.max_students:
                self.students.append(student)
                return True
            return False

        def get_average_grade(self):
            value = 0
            for student in self.student:
                value += student.get_grade()

            return value / len(self.students)
        
s1 = Student("Tim", 19, 95)
s2 = Student("Aaryan", 19, 100)
s3 = Student("Hayden", 19, 75)



c1 = Coures("Science", 2)
c1.add_student("science",2)
c1.add_student(s2)
print(c1.add_student(s3))
print(c1.get_average_grade())


       

5
class Object:
    #__init__() is called when you create an Object class
    def __init__(self,arg):
        #stores argument in self
        self.arg = arg
        
    def printArg(self):
        #calls argument from self
        print(self.arg)
4
#Object oriented programming is when you create your own custom class.
#One reason you should do this is that is saves you time.
#Another reason is it makes calling certain functions easier with tkinter

class Dog:
  #init creates certain parameters that allow you to define information quickly.
  def __init__(self, name):
    self.name = name
    
  def get_name(self):
	return self.name
    
if __name__ == "__main__":
  d = Dog(str(input("name your dog: "))
  print(d.get_name())
  
2
# A simple example class 
class Test: 
      
    # A sample method  
    def fun(self): 
        print("Hello") 
  
# Driver code 
obj = Test() 
obj.fun() 
1
# Object Oriented programing
# for begginer in python 3
# and advanced in python 

class Student():
    def __init__(self, name, age, grade):
        self.name = name
        self.age = age
        self.grade = grade # 0- 100

    def get_grade(self):
        return self.grade


class Coures:
    def __init__(self, name, max_students):
        self.name = name
        self.max_students = max_students
        self.students = []

        def add_student(self, student):
            if len(self.students) < self.max_students:
                self.students.append(student)
                return True
            return False

        def get_average_grade(self):
            value = 0
            for student in self.student:
                value += student.get_grade()

            return value / len(self.students)
        
s1 = Student("Tim", 19, 95)
s2 = Student("Aaryan", 19, 100)
s3 = Student("Hayden", 19, 75)



c1 = Coures("Science", 2)
c1.add_student("science",2)
c1.add_student(s2)
print(c1.add_student(s3))
print(c1.get_average_grade())
1

New to Communities?

Join the community