Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python not returning what I expected

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading