0

My program first asks the user what is wrong with their mobile phone and when the user writes their answer, the program detects keywords and outputs a solution. I used "or" statements but when I input "My phone dropped in water and my speakers don't work" it should output "you need new speakers. if waters been in contact you also may need a new motherboard if it doesn't come on" but instead it outputs "you will need your screen replacing"

Can anybody tell me what I'm doing wrong and tell me how I can overcome this problem in the future.

import time #This adds delays between questions
name = input ("what is your name?")
problem1 = input("hello there,what is wrong with your device?")
if "cracked" or "screen broke" in problem1:
    print("you will need your screen replacing")
elif "water" or "speakers" in problem:
    print("you need new speakers. if waters been in contact you also may need a new motherboard if it doesnt come on")
StephenTG
  • 2,579
  • 6
  • 26
  • 36
  • change problem to problem1 in you elif condition. – Jay T. Feb 24 '16 at 14:46
  • The cell phone repair industry is [really](http://stackoverflow.com/questions/35584784/how-to-make-a-list-go-to-a-def) [taking off](http://stackoverflow.com/questions/35525074/how-do-i-split-the-solutions-in-my-code) recently ;-) – Kevin Feb 24 '16 at 14:50

1 Answers1

0

I think you mis-understand or. In programming, or is slightly different from in English. x or y in z means "is x True or is y in z?". If the first argument (x) is non-empty, that means that it evaluates to True. No check is made for anything's presence in z. If x is empty, it evaluates to False and there is a check for y's presence in z, but not x's presence. You need to create a new test for each one. Also, you used problem instead of problem1 in your second elif:

if "cracked" in problem1 or "screen broke" in problem1:
    ...
elif "water" in problem1 or...
    ...
zondo
  • 19,901
  • 8
  • 44
  • 83
  • Actually, I'm fairly sure what's happening is not that True and False aren't in problem1, it's that "cracked" is truthy, and the or is short circuiting – StephenTG Feb 24 '16 at 14:49
  • I just tested; you are right. I'll edit my answer right away. Thanks. – zondo Feb 24 '16 at 14:51