Design a schedule class for classes that a student takes during a semester?

This is not a homework

`class schedule:
    def classes(self, course, points, level,):
        self.course= course
        self.points = points
        self.level = level
    def get_course(self):
         return course.name`

I am stock here

Recommended Answers

All 3 Replies

At this point you may want to actually study up on Python classes, you are making some major mistakes.

class Schedule:
    def __init__(self, course, points, level):
        self.course= course
        self.points = points
        self.level = level

    def get_course(self):
        return self.course

# create instances
# Schedule(course, points, level)
sched1 = Schedule("Programming101", 4, 1)
sched2 = Schedule("British103", 5, 3)
sched3 = Schedule("Biology102", 2, 1)

print(sched3.get_course())  # Biology102
# or
print(sched3.course)

print(sched1.points)  # 4

Thanks for help again and yes I am studying python classes, just didn't click in my head yet

Here is a class example that has helped a fair number of students ...

# a look at Python's class constructor, method and instance
# class names are capitalized by convention to aid readability

class Animal:
    def __init__(self, animal, sound):
        """
        The constructor __init__() brings in external
        parameters when an instance of the class is created,
        self keeps track of the specific instance and makes
        instance variables global to the class so the class
        methods can use them
        """
        self.animal = animal
        self.sound = sound

    def animal_sound(self):
        """
        a class method has self for the first argument
        note that self.animal and self.sound are global 
        to the class and specific to the instance
        """
        print( "The %s goes %s" % (self.animal, self.sound) )


# create an instance of the class
# you have to supply the animal and it's sound
# as shown in the class __init__() method
cow = Animal('cow', 'mooh')

# create another instance
dog = Animal('dog', 'woof')

# now let's do something with each instance
# the instance name is dot_connected to the method
cow.animal_sound()  # The cow goes mooh

dog.animal_sound()  # The dog goes woof
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.