Python OR command problem

Announcements Posted on
    • Thread Starter
    Offline

    0
    ReputationRep:
    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
    Offline

    2
    To add an 'or' clause, you'd need to format it like this:

    if "cracked" in problem or "<some other text>" in problem:
    ...
    Offline

    3
    ReputationRep:
    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.
    • Thread Starter
    Offline

    0
    ReputationRep:
    Thanks alot😂😂


    Posted from TSR Mobile
    Offline

    3
    ReputationRep:
    (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)
    Offline

    3
    ReputationRep:
    (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.
    Offline

    3
    ReputationRep:
    (Original post by Aklaol)
    They're not arguments, they're conditions.
    Corrected.
 
 
 
Write a reply… Reply
Submit reply

Register

Thanks for posting! You just need to create an account in order to submit the post
  1. this can't be left blank
    that username has been taken, please choose another Forgotten your password?
  2. this can't be left blank
    this email is already registered. Forgotten your password?
  3. this can't be left blank

    6 characters or longer with both numbers and letters is safer

  4. this can't be left empty
    your full birthday is required
  1. Oops, you need to agree to our Ts&Cs to register
  2. Slide to join now Processing…

Updated: October 15, 2016
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

Today on TSR
Poll
How are you feeling about doing A-levels?
Useful resources

Study tools

Rosette

Essay expert

Learn to write like a pro with our ultimate essay guide.

Thinking about uni already?

Thinking about uni already?

See where you can apply with our uni match tool

Student chat

Ask a question

Chat to other GCSE students and get your study questions answered.

Creating

Make study resources

Create all the resources you need to get the grades.

Planner

Create your own Study Plan

Organise all your homework and exams so you never miss another deadline.

Resources by subject

From flashcards to mind maps; there's everything you need for all of your GCSE subjects.

Papers

Find past papers

100s of GCSE past papers for all your subjects at your fingertips.

Help out other students

Can you help? Study help unanswered threads

Groups associated with this forum:

View associated groups
Study resources

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Quick reply
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.