In: Computer Science
# Do not delete this cell. You have to run this cell to test
your code in the test cases.
score = dict()
# This function will search the given text in order to find a given word
def is_word_there(text, word):
"""
What it takes?
a text to be searched
a word to be searched within a text
what it does?
searches if a word occurs in a text
What it returns?
returns 1 if word is in the text.
returns -1 if word is not in the text
"""
# your code goes in here
return
Test Case for Question 1. Do not delete or alter the cell below
score = dict()
text = """ Python is an amazing programming language.
Python is also one of the primary languages in the data analysis
field"""
word = "amazing"
try:
if is_word_there(text, word) ==1:
score['question 1'] =
'pass'
else:
score['question 1'] =
'fail'
except:
score['question 1'] = 'fail'
is_word_there(text, word)
# Do not delete this cell. You have to run this cell to test your code in the test cases.
# This function will search the given text in order to find a given word
def is_word_there(text, word):
"""
What it takes?
a text to be searched
a word to be searched within a text
what it does?
searches if a word occurs in a text
What it returns?
returns 1 if word is in the text.
returns -1 if word is not in the text
"""
# your code goes in here
text_to_array = text.split()
if word in text_to_array:
return 1
else:
return -1
score = dict()
text = """ Python is an amazing programming language. Python is also one of the primary languages in the data analysis field"""
word = "amazing"
try:
if is_word_there(text, word) == 1:
score['question 1'] = 'pass'
else:
score['question 1'] = 'fail'
except:
score['question 1'] = 'fail'
is_word_there(text, word)
# test command
print(score)
