+ 2
Why is my code saying undefined variable
def search(word, text): word=str(input()) text=str(input()) if word in text: print(search(text, word)) print ("Word found") else: print("Word not found")
1 Respuesta
+ 2
# as you doesn't indent if else statements, there are executed outside of the search function, where word is not accessible ^^
# also, you don't have to use arguments if you get user input...
def search():
word=str(input())
text=str(input())
if word in text:
print ("Word found")
else:
print("Word not found")
# obviously, you need to call the function to execute its code:
search()
# Jackson Kairani Maina I have too removed the line attempting to print result of inner function call ;P