0
Is this correct implementation for - Create a Car class and as a user I want to use the car .So I need to get into the car
#python class Person:pass class Car: persons=[] def get_in(self,person:Person): self.persons.append(person)
4 Respuestas
+ 1
Basically, except youre missing the init method. look at this code, I cant save it here right now
class Person:
def __init__(self,fname,lname):
self.fname = fname
self.lname = lname
class Car:
def __init__(self):
self.passengers = []
def get_in(self, person):
self.passengers.append(person)
print(f"{person.fname} got in the car!")
if __name__ == "__main__":
billy = Person("Billy","Bob")
sally = Person("Sally","Mae")
car = Car()
car.get_in(billy)
print("Passengers:")
for p in car.passengers:
print(p.fname,p.lname)
car.get_in(sally)
print("Passengers now:")
for p in car.passengers:
print(p.fname,p.lname)
0
Slick According to requirement it does not specify whether the person who wants to get in , is a passenger or driver correct me if I'm wrong
0
That is correct
0
I see right definition of a class here, but you ask me if the implementation is ok?