-2

So I'm testing out a Search History program on Python and its pretty basic, you search 5 different things one after another and then it asks whether or not you would like to show your Browsing History, so if you type in "yes" it displays it, but if I put "no" it still displays it.

So I have added several different "ifs, elif, and else" functions but none have worked

print "Check Browsing History?"

Check = raw_input()

if Check == "Yes" or "Yeah" or "Sure" or "yes" or "yeah" or "sure":

    print Search1 + "," ,
    print Search2 + "," , 
    print Search3 + "," , 
    print Search4 + "," , 
    print Search5 + "."
else:
    if Check == "No" or "Nope":

        print"OK"

When its "yes" it's supposed to display the 5 recent Search History and when its "no" it just says "ok" and the program ends.

Instead, when you type "yes" it does display the 5 recent Search History's but it does the same thing if you type "no"

There are no Error messages because the program "works"

Maurice Meyer
  • 17,279
  • 4
  • 30
  • 47
  • 3
    This is not how you do multiple conditionals in python – G. Anderson May 22 '19 at 20:20
  • not sure why this was downvoted, it is a duplicate but that shouldn't merit downvotes, is perfectly fine question as far as I can tell... – DrCord May 22 '19 at 20:23
  • what if the input is `'yEs'`? if all you care about is yes/no, then prompt the user to enter yes/no. ignore case by doing `if Check.lower().strip()[0] == 'y'` and consider *anything* else to be a "no" response. – David Zemens May 22 '19 at 20:25

1 Answers1

0

Make sure you are entering everything correctly, it is case sensitive. Also, your if condition is not correct. The correct way to check multiple if condition is : itemToCheck == valueToCheck or itemToCheck == anotherValueToCheck and so on.

def main():
  check = input("Enter")
  if (check == "yes" or check == "yah"): <-- you can include more items here
    print(Search1, ",", Search2, ",")
  elif (check == "no"):
    print("ok")

main()
Maddy
  • 2,025
  • 5
  • 26
  • 59
  • reason for downvote? – Maddy May 22 '19 at 20:22
  • 1
    `if check in ("yes","yah", ...)` also probably a good idea to `lower().strip()` the input to reduce the number of comparisons you need to make, or since we're talking about y/n responses, just take the `check[0]` and test if it's `'y'`. – David Zemens May 22 '19 at 20:23
  • @DavidZemens, that is valid but not sure if the OP wants the program to run that way. checking for `check[0]` is a great solution. – Maddy May 22 '19 at 20:25
  • 1
    not sure, but pretty sure OP doesn't know how he wants the program to run based on the snippets of code provided. `Search1` through `Search5` instead of storing several searches in a list? Upper-case names? 99% of the time you'd want to treat "Yes" == "yes" == [any other variation on casing of that word, plus whitespace], so the `lower().strip()` helps foolproof your user-input. But the `in` test is almost certainly better than a succession of `or` statements and it's objectively more readable. – David Zemens May 22 '19 at 20:30