Users Online

· Guests Online: 15

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

Articles Hierarchy

Leccture 8

In-Class Questions and Video Solutions

Lecture 8

  1. Class Definition

    Which of the following is a good and valid definition for a class representing a car?

     

       

     

  2. Class Instance

    Using the class definition below, which line creates a new Car object with 4 wheels and 2 doors?

    class Car(object):
        def __init__(self, w, d):
            self.wheels = w
            self.doors = d
            self.color = ""
    

     

       

     

  3. Methods

    Which of the following methods changes the color of the car, based on the definition below?

    class Car(object):
        def __init__(self, w, d):
            self.wheels = w
            self.doors = d
            self.color = ""
    

     

       

     

  4. Method Call

    You create a car with mycar = Car(4, 2). Which is a line of code to change the color of mycar to “red”?

    class Car(object):
        def __init__(self, w, d):
            self.wheels = w
            self.doors = d
            self.color = ""
        def paint(self, c):
            self.color = c
    

     

       

     

  5. Special Methods

    With the code below, what does the line print(mycar == yourcar) print?

    class Car(object):
        def __init__(self, w, d):
            self.wheels = w
            self.doors = d
            self.color = ""
        def paint(self, c):
            self.color = c
        def __eq__(self, other):
            if self.wheels == other.wheels and \
                self.color == other.color and \
                self.doors == other.doors:
                return True
            else:
                return False
    
    mycar = Car(4, 2)
    mycar.paint("red")
    yourcar = Car(4,2)
    print(mycar == yourcar)
    

     

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 1.07 seconds
14,414,601 unique visits