I'm currently learning Python and I have a question which I cannot find the answer too, currently I am trying to take a string variable given from the user and comparing it to part of another string. I want something like this:
Program: The given sentence is "I like chemistry", enter a word in the sentence given.
User: like
Program: Your word is in the sentence.
I can only seem to make a program using the if
function and ==
but this only seems to recognize that the two strings are similar if I type the full sentence given by the program.
From the some of the answers I have changed my program to but there seems to be an error I cannot find.
sentence=("I like chemistry")
print("The given sentence is: ",sentence)
word=input("Give a word in the sentence: ").upper
while word not in sentence:
word=input("Give a valid word in the sentence: ")
if word in sentence:
print("valid")