-2

I am trying to make a simple food game/questionnaire, and the code keeps printing both lines. I want to have it print one or the other, and no matter what I try, I get the same end result. I am also using Tkinter. (Those of you that do not know, don't worry... This is for those that know what Tkinter does/is.)

Here is my code:

def Waffles():

    input ("Do you like Waffles?          ")
    if input is not ('yes'):
        print ("Ok, so you don't like Waffles...")
    input ("Do you like Pancakes?             ")
    if input is not ('no'):
        print ("Then let's fix some!!!")
    if input is ("no") or ("No"):
        print ("Ok, so you don't like Pancakes...")
    input ("Do you like French Toast?          ")
    if input is not ("no"):
        print ("Then let's fix some!!!")
    if input is not 'yes':
        food = input ("Then what do you like?         ")
        print ("Oh! Ok.")

Here is what gets printed:

Do you like Waffles?          no
Ok, so you don't like Waffles...
Do you like Pancakes?             no
Then let's fix some!!!
Ok, so you don't like Pancakes...
Do you like French Toast?          no
Then let's fix some!!!
Then what do you like?         food
Oh! Ok.

Can you help me make this print one or the other? ("Then let's fix some!!!" and "Do you like __________").

I_Like_PI
  • 3
  • 3
  • The code above has _nothing_ to do with [tag:tkinter]. – Nae Feb 06 '18 at 23:23
  • I fixed the tag, but this code is in a Tkinter window as a button... So, I added it with Tkinter. – I_Like_PI Feb 06 '18 at 23:25
  • 4
    "Yes, I did my research" No, you didn't. If you had, you would know that that's not even close to how `input` works. See [here](https://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/io.html). And also, [don't use `is` to compare strings.](https://stackoverflow.com/questions/1504717/why-does-comparing-strings-in-python-using-either-or-is-sometimes-produce) – internet_user Feb 06 '18 at 23:26
  • 2
    you need to capture the results of the input function as a variable – Paul H Feb 06 '18 at 23:27
  • I am very very basic at using python, thank you for the input. – I_Like_PI Feb 06 '18 at 23:29
  • `True or anything` is always `True`, and `("no")` is _never_ `False`. – Nae Feb 06 '18 at 23:37

2 Answers2

1

"input" is a function. So you are testing if the built-in function is (or is not) various strings, which it never is.

You need to store the result of "input" in a variable and test that. Here's a simplified version of Waffles() demonstrating the concept.

def Waffles():
  answer = input ("Do you like Waffles?          ")
  if answer != 'yes':
      print ("Ok, so you don't like Waffles...")

In case that isn't clear, here's a more contrived function that should really drive the example home.

def demonstrate_input():
    input("do you like waffles          ")
    print(input)
    answer = input("do you like waffles? I will remember this time         ")
    print(answer)

Here's what happens when you run that function:

do you like waffles          no
<built-in function input>
do you like waffles? I will remember this time         nope
nope

Note how printing "input" prints out a strange looking reference to the function, but printing "answer" returns the thing that was answered to the input prompt.

HarlandMason
  • 779
  • 5
  • 17
0

Here's how I would've written it:

def waffles():

    response = input("Do you like Waffles?\t\t\t")
    print(response.lower())
    if response.lower() != "yes":
        print("Ok, so you don't like Waffles...")

        response = input("Do you like Pancakes?\t\t\t")
        if response.lower() != "no":
            print("Then let's fix some!!!")
        else:
            print("Ok, so you don't like Pancakes...")
            response = input("Do you like French Toast?\t\t")
            if response.lower() != "no":
                print("Then let's fix some!!!")
            if response.lower() != "yes":
                input("Then what do you like?\t\t\t")
                print ("Oh! Ok.")

waffles()
Nae
  • 14,209
  • 7
  • 52
  • 79
  • What do you mean by \t\t\t – I_Like_PI Feb 06 '18 at 23:53
  • @I_Like_PI That's the `tab` character for aligning strings better. – Nae Feb 06 '18 at 23:53
  • Here is the new code (total program) – I_Like_PI Feb 06 '18 at 23:55
  • from tkinter import * root = Tk() def Waffles(): input ("Do you like Waffles? ") if answer is "False": print ("Ok, so you don't like Waffles...") input ("Do you like Pancakes? ") if answer is "yes" or "Yes": print ("Then let's fix some!!!") elif answer is "False": print ("Ok, so you don't like Pancakes...") input ("Do you like French Toast? ") if answer is "False": print ("Then let's fix some!!!") elif answer is "True": ... – I_Like_PI Feb 06 '18 at 23:56
  • elif answer is "True": food = input ("Then what do you like? ") print ("Oh! Ok.") #works like it is supposed to (THIS LINE ONLY) – I_Like_PI Feb 06 '18 at 23:57
  • character limit on comments... – I_Like_PI Feb 06 '18 at 23:57
  • Thank you so much Nae for the help!!! the `waffles()` part didn't help... It was supposed to run, when the user pressed a button in Tkinter, but I got it to work... – I_Like_PI Feb 08 '18 at 23:15