The Student Room Group

Python OR command problem

This is my code:
problem=input("Please state the issue with your phone")

if "cracked" in problem:
print("Replace screen")

elif "battery" in problem:
print("Replace battery")

elif "speaker" in problem:
print("Replace speaker")

elif "charger" in problem:
print("Please replace your charger")

elif "camera" in problem:
print("Replace the camera module")

else:
print("Please go to manufacturers")
And the problem is that whenever i add more keywords with an 'or' inbetween the program simply doesnt work
Reply 1
To add an 'or' clause, you'd need to format it like this:

if "cracked" in problem or "<some other text>" in problem:
...
the "or" clause simply takes two booleans (or expressions that evaluate to booleans) and returns another one. To use it in this case, you need two expressions that returns booleans eg. elif "camera" in problem or "....." in problem. You can't say elif "camera" or "...." in problem. Or doesn't work like that.
Reply 3
Thanks alot😂😂


Posted from TSR Mobile
Original post by Rahat.H
This is my code:
problem=input("Please state the issue with your phone":wink:

if "cracked" in problem:
print("Replace screen":wink:

elif "battery" in problem:
print("Replace battery":wink:

elif "speaker" in problem:
print("Replace speaker":wink:

elif "charger" in problem:
print("Please replace your charger":wink:

elif "camera" in problem:
print("Replace the camera module":wink:

else:
print("Please go to manufacturers":wink:
And the problem is that whenever i add more keywords with an 'or' inbetween the program simply doesnt work

An or statement returns True, if any given condition is true. (as opposed to and, which returns True only if all given conditions are true)
(edited 7 years ago)
Reply 5
Original post by _gcx
An or statement returns True, if any given argument is true. (as opposed to and, which returns True only if all given arguments are true)


They're not arguments, they're conditions.
Original post by Aklaol
They're not arguments, they're conditions.


Corrected.

Quick Reply

Latest