Rahat.H
Badges: 0
Rep:
?
#1
Report Thread starter 3 years ago
#1
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
0
reply
trythis
Badges: 11
Rep:
?
#2
Report 3 years ago
#2
To add an 'or' clause, you'd need to format it like this:

if "cracked" in problem or "<some other text>" in problem:
...
0
reply
BobBobson
Badges: 3
Rep:
?
#3
Report 3 years ago
#3
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.
0
reply
Rahat.H
Badges: 0
Rep:
?
#4
Report Thread starter 3 years ago
#4
Thanks alot😂😂


Posted from TSR Mobile
0
reply
_gcx
Badges: 19
Rep:
?
#5
Report 3 years ago
#5
(Original post by Rahat.H)
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
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)
0
reply
Aklaol
Badges: 12
Rep:
?
#6
Report 3 years ago
#6
(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.
0
reply
_gcx
Badges: 19
Rep:
?
#7
Report 3 years ago
#7
(Original post by Aklaol)
They're not arguments, they're conditions.
Corrected.
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

University open days

  • The University of Law
    Solicitor Series: Assessing Trainee Skills – LPC, GDL and MA Law - Exeter campus Postgraduate
    Thu, 27 Feb '20
  • University of East Anglia
    PGCE Open day Postgraduate
    Sat, 29 Feb '20
  • Edinburgh Napier University
    Postgraduate Drop-in Brunch Postgraduate
    Sat, 29 Feb '20

Do you get study leave?

Yes- I like it (274)
60.89%
Yes- I don't like it (22)
4.89%
No- I want it (120)
26.67%
No- I don't want it (34)
7.56%

Watched Threads

View All