Python Forum
Made a Class, How to Continue?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Made a Class, How to Continue?
#1
Okay, the first part of my assignment was to make a Class called Car. I have done this with the data attributes and methods they told me to use:

class Car():
    def __init__(self, year_model, make):
        self.__year_model = year_model
        self.__make = make
        self.__speed = 0

    def accelerate(self):
        self.__speed += 5
    def brake():
        if self.__speed >=5
           self.__speed -= 5
        else:
            print 'Error, you are not moving'
            
    def get_speed():
        return self.__speed
I did this the day of my class, when everything was fresh in my mind. I still have to make an accompanying program with this for the assignment that creates a Car object then calls the accelerate method five times and display the new car speed after each accelerate method then do the same with the brake method. However, my mind is so foggy now that I can't remember how to do it.

Can someone help me with this last half of the assignment I need to do or at least help me start out? I'd really appreciate it.
Reply
#2
first step would be to make an instance of your class, something like:
my_awesome_car = Car(year_model=2017, make='Ferrari')
and start 'driving' your awesome car, i.e. using different methods you have as per the assignment
Reply
#3
(Nov-04-2017, 05:58 AM)buran Wrote: first step would be to make an instance of your class, something like:
my_awesome_car = Car(year_model=2017, make='Ferrari')
and start 'driving' your awesome car, i.e. using different methods you have as per the assignment

Thanks for that. The starter really helped.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020