samedi 10 octobre 2020

How to correctly use a series of independent if statements in python to get correct output?

I am aware of the if-elif-else route but I felt this should work too. please help me find my mistake. Made several attempts and finally no longer getting syntax or indentation errors but still getting wrong output.

My code:

cars = [ 'Audi' , 'bMw' , 'mercedes' , 'toyota' , 'soobie' ]

for car in cars:
    if car.lower() == 'bmw':
        print(car.upper())
        print("Your car's fast")

    if car.lower() == 'soobie':
        print("Subaru")
        print("You're probably a ricer")

    if car.lower() != 'bmw' and car.lower() in cars != 'soobie':
        print(car.title())
        print("Good choice!")

Intended output:

Audi

Good choice!

BMW

Your car's fast

Mercedes

Good choice!

Toyota

Good choice!

Subaru

You're probably a ricer

Aucun commentaire:

Enregistrer un commentaire