Wrong if/elif output PYTHON


#1

Please leave the following link in the post so we can find the unit module, else replace it with a link to the exact lesson:

Strings and Console Output

Ok so I am new to Python and I made this code.


print colored("We will calculate a perfect car that suits your needs.","cyan")
interest = raw_input()
print colored("Which engine do you desire?","cyan")
engine = raw_input()
print colored("What color do you want?","cyan")
color = raw_input()

print colored("Would you like a muscle car, sports car, super car, or an ATV?","cyan")
car = raw_input()
if color == "Red" or color == "RED" or color == "red" and car == "MUSCLE" or car == "muscle" or car == "Muscle":
    t = colored("That will be 75,000$","red")
elif color == "Blue" or color == "blue" or color == "BLUE" or car == "sports" or car == "SPORTS" or car == "Sports":
    t = colored("That will be 82,000$","red")
elif color == "Blue" or color == "BLUE" or color == "blue" or car == "muscle" or car == "MUSCLE" or car == "Muscle":
    t = colored("That will be 75,000$","red")
elif color == "Red" and car == "sports":
    t = colored("That will be 81,000$","red")
elif color == "Blue" and car == "ATV":
    t = colored("That will be 55,000$","red")
elif lcolor == "Red" and car == "ATV":
    t = colored("That will be 54,000$","red")
elif color == "Red" and car == "super":
    t = colored("That will be 95,000$","red")
elif color == "Blue" or color == "BLUE" or color == "blue" and car == "super" or car == "SUPER" or car == "Super":
    t = colored("That will be 96,000$",)
print colored("You want a %s engine , the color to be %s and the car to be a %s car. %s.","yellow") % (engine, color, car, t)

whenever I use it , it always outputs the wrong information


#2

what library are you using for colored? I tried this one:

https://pypi.python.org/pypi/colored

which is not working, so i can’t run the code, can you show me when and how the output is wrong? Describe it to me?

this comparison:

if color == "Red" or color == "RED" or color == "red" and car == "MUSCLE" or car == "muscle" or car == "Muscle":

only one of these conditions has to be true. So if the car is either red or muscle, the condition is satisfied

isn’t it easier to convert the user input to lowercase:

color = raw_input().lower()

same for car, and then simply do:

if color == "red" and car == "muscle":

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.