Question

2) Write a class to represent a class to represent a Car and its passengers. Write a constructor that takes one additional pa

I need help asap, Python language

0 0
Add a comment Improve this question Transcribed image text
Answer #1

                       ANSWER : HERE IS THE ANSWER FOR YOUR QUESTION:

  

                       ------------------------------------------------------------------------------------------------------

        CODE:


#creating a class as CAR
class Car:
l=[]
#defining constructor
def __init__(self, no):
self.no = no
self.l=[]
#defining totalRiders method
def totalRiders(self):
return self.no
#defining addRider method   
def addRider(self,name):
if len(self.l)<2:
self.l.append(name)
return Tru

                       -------------------------------------------------------------------------------------------------------                

                  SNIPPET

12 main.py 1 2 #creating a class as CAR 3. class Car: 4 1=[] 5 #defining constructor 6 def _init__(self, no): 7 self.no = no

                      ---------------------------------------------------------------------------------------------------------

                  OUTPUT

True True False 2 ... Program finished with exit code o Press ENTER to exit console.]

                       -------------------------------------------------------------------------------------------------------

I hope this would help you out.

If you like my answer , please upvote

If you have any doubt, you can provide comment /feedback below the answer

Thanks

Add a comment
Know the answer?
Add Answer to:
I need help asap, Python language 2) Write a class to represent a class to represent...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Assume you have a Car class that declares two private instance variables, make and model....

    1. Assume you have a Car class that declares two private instance variables, make and model. Write Java code that implements a two-parameter constructor that instantiates a Car object and initializes both of its instance variables. 2. Logically, the make and model attributes of each Car object should not change in the life of that object. a. Write Java code that declares constant make and model attributes that cannot be changed after they are initialized by a constructor. Configure your...

  • Python vUniess you need to edit, it's safer to stay in Enable Editing Propiem 1 Write...

    Python vUniess you need to edit, it's safer to stay in Enable Editing Propiem 1 Write a class definition line and a one line docstring for the class Dog. Write an_ nit_ method for the class Dog that gives each dog its own name and breed. Test this on a successful creation of a Dog object import dop sugar dog.Dog( Sugar, border collie) >>>sugar.name Sugar >sugar.breed Problem 2 Add a data attribute tricks of type list to each Dog instance...

  • Write a class called Player that has four data members: a string for the player's name,...

    Write a class called Player that has four data members: a string for the player's name, and an int for each of these stats: points, rebounds and assists. The class should have a default constructor that initializes the name to the empty string ("") and initializes each of the stats to -1. It should also have a constructor that takes four parameters and uses them to initialize the data members. It should have get methods for each data member. It...

  • Python 3 Problem: I hope you can help with this please answer the problem using python...

    Python 3 Problem: I hope you can help with this please answer the problem using python 3. Thanks! Code the program below . The program must contain and use a main function that is called inside of: If __name__ == “__main__”: Create the abstract base class Vehicle with the following attributes: Variables Methods Manufacturer Model Wheels TypeOfVehicle Seats printDetails() - ABC checkInfo(**kwargs) The methods with ABC next to them should be abstracted and overloaded in the child class Create three...

  • 10q I need help this is a python language For the following question, refer to the...

    10q I need help this is a python language For the following question, refer to the Python module on the right, as well as the name of the file that contains each module. 1) What is the output of the following code?. import animals alist = [animals.cat('Garfield'), animals.Dog('odie'), animals. Fox ('Nicholas P. wilde'), animals. Animal ('Judy Hopps')] File animals.py class Animal: def _init__(self, name): self.name = name def getName(self): return self.name for a in alist: print( a.getName() + ', '...

  • Question 11 (20 points) Given the class Point below, define a class Circle that represent a...

    Question 11 (20 points) Given the class Point below, define a class Circle that represent a circle with a given center and radius. The circle class should have a center attribute named center as well as a floating point radius attribute. The center is a point object, defined by the class Point. The class should also have these members: the constructor of the class, which should take parameters to initialize all attributes - a getter for center a setter for...

  • You are allowed to add any parameter you need into any class. You are not allowed...

    You are allowed to add any parameter you need into any class. You are not allowed to DELETE any mentioned parameter in the question. Use comments to explain your code Your code should be runnable. You can copy-paste your code here, or upload a zip file of your files. Inheritance rules must be considered. The super() method should be used where necessary. You should prevent the creation of instances (i.e. objects) Casting must also be considered where necessary. You should...

  • Please use C++. Write a class named Circle that has a double data member named radius...

    Please use C++. Write a class named Circle that has a double data member named radius and a static double data member named maxRadius. It should have a default constructor that initializes the radius to 1.0. It should have a constructor that takes a double and uses it to initialize the radius. It should have a method called calcArea that returns the area of the Circle (use 3.14159 for pi). It should have a static set method for the maxRadius....

  • Create a class called Date212 to represent a date. It will store the year, month and...

    Create a class called Date212 to represent a date. It will store the year, month and day as integers (not as a String in the form yyyymmdd (such as 20161001 for October 1, 2016), so you will need three private instance variables. Two constructors should be provided, one that takes three integer parameters, and one that takes a String. The constructor with the String parameter and should validate the parameter. As you are reading the dates you should check that...

  • Write a class called Point that contains two doubles that represent its x- and y-coordinates. It...

    Write a class called Point that contains two doubles that represent its x- and y-coordinates. It should have get and set methods for both fields. It should have a constructor that takes two double parameters and initializes its coordinates with those values. It should have a default constructor that initializes both coordinates to zero. It should also contain a method called distanceTo that takes as a parameter another Point and returns the distance from the Point that was passed as...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT