New Programmer/Need assistance with if statements - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: New Programmer/Need assistance with if statements (/thread-10518.html) |
New Programmer/Need assistance with if statements - KayPyth - May-23-2018 Hi Everyone---New programmer. I am trying to create a program that helps women locate good products for their hair type. I just got started and I am running into a few issues. If my code makes sense I am trying to display a specific response depending on the letter answer they give. Unfortunately my code keeps printing out all the answers at once, no matter which letter is selected. I have posted the code below and the errors that I am getting. I am almost positive there is an issue with my if statements: print ("Let's help you choose you hair texture") print ("") Hair_Quiz = input("What is your hair color? ") print ("") if Hair_Quiz == "black" or " dark brown": print (" A) Upper case S shape curl") print (" B) Coarse Upper case S springy ringlets") print (" C) Tight corkscrew like curls similiar to the size of a straw or pencil") print (" D) Thick, coarse S shaped springs coils similiar to the size of a coffee straw") print (" E) Tightly packed dense springy coils that have a definite curl shape") print (" F) Densly packed coils simialir to the shape of a Z") print ("") q1 = input("What kind of curls do you have? ") if q1 == "A" or "a": print (" You have 3A textured hair") if q1 == "B" or "b": print ("You have 3B textured hair") if q1 == "C" or "c": print ("You have 3C textured hair") if q1 == "D" or "d": print ("You have 4A textured hair") if q1 == "E" or "e": print ("You have 4B textured hair") if q1 == "F" or "f": print ("You have 4C textured hair")What is happening when I run the module:
RE: New Programmer/Need assistance with if statements - buran - May-23-2018 https://python-forum.io/Thread-Multiple-expressions-with-or-keyword RE: New Programmer/Need assistance with if statements - KayPyth - May-23-2018 Went to link and I am still confused. I have searched Google and stack overflow for assistance and still cannot figure out why it won't work. RE: New Programmer/Need assistance with if statements - buran - May-23-2018 if q1 == "A" or "a" will always be evaluated as True , because any non-empty string (in this case "a") is evaluated as True , so it is same as if q1 == "A" or True: it should be if q1 == "A" or q1 == "a": . Same apply to rest of your if statements.Finally, there are better ways to do ot, not using number of if statements hair = {'a':'3A textured hair', 'b': '3B textured hair', 'c':'3C textured hair', 'd':'4A textured hair', 'e': '4B textured hair', 'f':'4C textured hair'} q1 = input("What kind of curls do you have? ") print('You have {}'.format(hair.get(q1.lower(), 'unknown textured hair'))) RE: New Programmer/Need assistance with if statements - KayPyth - May-23-2018 Thank you!!!! I knew it was something small I was doing wrong and of course I knew there had to be an easier way but just trying to use what I've learned so far. Again, thanks for your help :) |