Third day of learning Python. Code is not returning what I expected. I am working on an code that shows passengers added and passengers not added to flight. If I remove "no avaiable seats," code will return passengers added. I am trying to get both added passengers and no seats available to return.
class Flight():
def __init__(self, capacity):
self.capacity = capacity
self.passengers = []
def add_passenger(self, name):
if not self.open_seats():
return False
self.passengers.append(name)
return True
def open_seats(self):
return self.capacity - len(self.passengers)
flight = Flight(3)
people = ["Huey", "Duey", "Luey", "Uncle Scrooge",]
for person in people:
success = flight.add_passenger(person)
if success:
print(f"Added {person} to flight successfully")
else:
print(f"No available seats for {person}")
>Solution :
Your If and Else statements should be on the same indentation as success, since you’re using the iterating variable in the "no available seats" statement.