-2

I'm trying to solve this and the ("display" or "screen") works fine but i can't get the other part to work as it simply stops the code. Just in case the link doesn't work here it is:

if ("display" or "screen") and ("broken" or "blank" or 'black') in problem: 
    print('So your screen is broken? interesting.')
Noctis Skytower
  • 21,433
  • 16
  • 79
  • 117
  • Actually, if "works fine" means "does what you think," no part of that works fine. – TigerhawkT3 May 23 '16 at 09:35
  • it does as when I type in " my display is broken" It works (the print bit is indented) – cheesenibbles May 23 '16 at 09:36
  • Try something that doesn't include "display" or "broken" and you will see that the program can't tell. – TigerhawkT3 May 23 '16 at 09:37
  • it works with screen, it's the other bit (blank or black) that i'm trying to figure out what to replace with – cheesenibbles May 23 '16 at 09:39
  • 2
    And I'm telling you that no, it does not work with "screen." Conduct more tests and you will see that the program always behaves the same way, because `if ("display" or "screen"):` always evaluates to true. – TigerhawkT3 May 23 '16 at 09:40
  • Also, have you done any research on Google? SO is full of questions about phone repair programs ([here](http://stackoverflow.com/questions/35516994/how-do-i-split-the-solutions-for-my-code), [here](http://stackoverflow.com/questions/35440277/how-can-i-put-keywords-into-my-code/35463021), [here](http://stackoverflow.com/questions/35413563/how-do-you-add-a-list-to-jump-to-a-line-on-my-code), etc.). – TigerhawkT3 May 23 '16 at 09:40
  • K, i'll take a look there then – cheesenibbles May 23 '16 at 09:42

2 Answers2

0

The problem with your code is that ("display" or "screen") returns "display" and ("broken" or "blank" or 'black') returns "broken", so you are not searching for what you want to be searching.

Try this:

if "display" in problem or "screen" in problem:
    if "broken" in problem or "black" in problem or "blank" in problem:
         print('So your screen is broken? interesting.')
Tonechas
  • 13,398
  • 16
  • 46
  • 80
Ma0
  • 15,057
  • 4
  • 35
  • 65
0

If you want to check if any number of sub-strings may be contained in a string, then you might want to take the following approach as a guide to a possible solution to solving the problem you are working on:

def main():
    problem = input('What is your problem? ')
    if in_(problem, 'display', 'screen') and \
            in_(problem, 'broken', 'blank', 'black'):
        print('So your screen is broken? Interesting.')


def in_(string, *substrings):
    return any(substring in string for substring in substrings)


if __name__ == '__main__':
    main()
Noctis Skytower
  • 21,433
  • 16
  • 79
  • 117