lundi 31 août 2015

For will not iterate through entire list in Python

so I'm learning Python and having trouble with this small program I've designed to try and take my Codecademy skills further.

car_models = ["Ferrari", "Lamborghini", "Aston Martin", "BMW"]
bad_cars = ["Toyota", "Mazda", "Ford", "Hyundai"]

for gcar, bcar in zip(car_models, bad_cars):
    ask = input("What is your favorite car brand? ")
    if ask == gcar:
        print("Yes!")
    elif ask == bcar:
        print("Ew!")
    else:
        print("The model is not listed")
    break

When I run this, it will only pop up with an answer if the model is the first one on the list, otherwise, it just tells you that the model is not listed even though it is.

Thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire