Don't Understand what I am doing wrong : Can someone help? - 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: Don't Understand what I am doing wrong : Can someone help? (/thread-14908.html) |
Don't Understand what I am doing wrong : Can someone help? - meekschr - Dec-23-2018 user=input("Hello, I am the computer. What is your name? : ") print("Hello,", user) user=input("Chris, do you enjoy programing? : ") print("I enjoy it as well. I happen to run on programs.") if "yes" else ("Why not : ?") user=input("What do you like to program? : " if "yes" else input("Why don't you enjoy programing? : "))On the fourth line, I am trying to get the computer to respond "Why not : ?" after I enter no, on the line above that. Every time I try to fix it and find out why it is not working, the computer keeps responding "I enjoy it as well. I happen to run on programs." Can someone please help me to understand what I am either missing or doing wrong. I am new to using Python and it is hard for me to find mistakes that I have made. Thank you. RE: Don't Understand what I am doing wrong : Can someone help? - Larz60+ - Dec-23-2018 if "yes": # you need to do something here. else: ("Why not : ?")same on line 5 RE: Don't Understand what I am doing wrong : Can someone help? - meekschr - Dec-23-2018 user=input("Hello, I am the computer. What is your name? : ") print("Hello,", user) user=input ("Chris, do you enjoy programing? : ") if "yes" : print("I enjoy it as well. I happen to run on programs") else : ("Why not : ?") ------------------------------------------------------ Hello, I am the computer. What is your name? : chris Hello, chris Chris, do you enjoy programing? : no I enjoy it as well. I happen to run on programs Process finished with exit code 0 I don't understand why the computer does not respond with "Why not : ?" RE: Don't Understand what I am doing wrong : Can someone help? - ichabod801 - Dec-24-2018 First of all, Larz pointed out that you need to post code in python tags, and gave you a link on how to do it. Fix that. Second, it's because you are only testing 'yes'. 'yes' is True, because all non-empty strings are True. You need to specify that you are testing to see if user is yes ( if user == 'yes': ), otherwise the computer has no idea what youare trying to do.
|