-2

I need to make the code below disregard any case sensitivity Here's the code:

sentence=str(input("Enter sentence")
words=sentence.split()
uword=input("enter word from sentence")
if uword in words:
    print("Word is in sentence")
else:
    print("Word isn't in sentence")

For example if I inputted the sentence "Hello World" as the sentence variable and then inputted "hello" as the uword variable the code should recognise that hello and Hello are the same and print (" Your word is in the sentence")

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
R Rodriguez
  • 45
  • 1
  • 5

1 Answers1

1

This feels kind of like the obvious answer:

Convert both strings to lower, or upper case:

words = sentence.lower().split()
…
if uword.lower() in words:
Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
  • Thanks a lot, Your suggestion works if the sentence variable is entered as "Hello World" and the uword variable is entered "hello" but can you tell me how to make it work so the sentence variable can be entered lower case and the uword variable entered lower case? Thanks again – R Rodriguez May 27 '16 at 13:03
  • It does work in that case, too. – Marcus Müller May 27 '16 at 13:06
  • I'm sorry but I can't seam to get it working that way, if the sentence variable is inputted all lower case and the uword variable is inputted with an upper case letter it doesn't work – R Rodriguez May 27 '16 at 13:09
  • 1
    uword is converted to lowercase by `uword.lower()`. There's nothing wrong with this code. – Marcus Müller May 27 '16 at 13:12