Jump to content
Killersites Community

Python course Ch 4 - flow control

Recommended Posts


I'm following video, and for some reason IF statement doesn't work properly:

def flow_control():
    answer = input("Do you want to learn about multiline text strings? (yes or no)")
    #if answer == "yes" or answer == "y":
    if answer == ("yes" or "y"):
        print("End program")

Commented out IF statement works perfectly well, but 2nd one work only for "yes".

How can i make it work? 


Share this post

Link to post
Share on other sites

i'm using PyCharm, in such cases i have red underline and code would not run properly.

I replaced tabs with 4 spaces, but it did not help at all.

    if answer == ("y" or "yes"):

I have replaced "y" with "yes" so answer is True only for "y" because for "yes" it going to else statement.

It looks my IDE does not consider "or".

PS. i was fooling around and changed or to and. In that case for answer is True for "yes".

Anyhow ill back to version without parentheses, just was curious what is going on in background.


Edited by Piotr

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now