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
  • 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...

  • 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...

  • I have to write a C program to assign seats on each flight of the airline’s...

    I have to write a C program to assign seats on each flight of the airline’s only plane (capacity: 40 seats, in 10 rows). For the sake of simplicity, assume that each row has 4 seats labeled A, B, C, D. Your program should display the following menu of alternatives: Please type 1 for "first class" Please type 2 for "business class" Please type 3 for “economy class”. If the person types 1, then your program should assign a seat...

  • 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...

  • 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...

  • I need to write a Java Programm based on the follwoing facts: A company that operates...

    I need to write a Java Programm based on the follwoing facts: A company that operates regional trains wants to model the utilization of their trains. For this she has created the following UML class diagram. Train -capacity:int -numberPassengers:int +Train(capacity:int) +getcapacity():int +getNumberPassengers();int +setNumberPassengers(numbersPassengers:int):void The exercise i need help with is as follows: Write a Java class train for the given class diagram and implement all the methods. The number of passengers of new instances should be 0. The method setNumberPassengers...

  • I need help with this problem. Using Python please. Thanks Construct a class “Monster” with the...

    I need help with this problem. Using Python please. Thanks Construct a class “Monster” with the following attributes: self.name (a string) self.type (a string, default is ‘Normal’) self.current_hp (int, starts out equal to max_hp) self.max_hp (int, is given as input when the class instance is created, default is 20) self.exp (int, starts at 0, is increased by fighting) self.attacks (a dict of all known attacks) self.possible_attacks (a dictionary of all possible attacks The dictionary of possible_attacks will map the name...

  • 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...

  • 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...

  • Need Help Please Using Java Language Create a Code Write a class (and a client class...

    Need Help Please Using Java Language Create a Code Write a class (and a client class to test it) that encapsulates the evolution of the passwords of three students over four months. Your only instance variable should be a two-dimensional array of values representing the passwords. Dimension 1 represents the student and dimension 2 represents the month. (Since we are concerned about security, we are assuming that people change their password once a month; we only care about the value...

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