Question
Write function called fancy_find. fancy_find should have #two parameters: search_within and search_for. # #fancy_find should check if search_for is found within the #string search_within. If
Write function called fancy_find. fancy_find should have
#two parameters: search_within and search_for.
#
#fancy_find should check if search_for is found within the
#string search_within. If it is, it should print the message
#"[search_for] found at index [index]!", with [search_for]
#and [index] replaced by the value of search_for and the
#index at which it is found. If search_for is not found
#within search_within, it should print, "[search_for] was
#not found within [search_within]!", again with the values
#of search_for and search_within.
#
#For example:
#
# fancy_find("ABCDEF", "DEF") -> "DEF found at index 3!"
# fancy_find("ABCDEF", "GHI") -> "GHI was not found within ABCDEF!"
#Add function here!
def fancy_find(search_within, search_for):
index = search_within.index(search_for)
if search_for in search_within:
return (search_for, "found at index", index)
else:
return (search_for, "was not found within", search_within, "!")
#Below are some lines of code that will test your function.
#You can change the value of the variable(s) to test your
#function with different inputs.
#
#If your function works correctly, this will originally
#print:
#DEF found at index 3!
#GHI was not found within ABCDEF!
print(fancy_find("ABCDEF", "DEF"))
print(fancy_find("ABCDEF", "GHI"))
'''''
The feedback:
('DEF', 'found at index', 3)
Traceback (most recent call last):
File "FancyFind.py", line 38, in
print(fancy_find("ABCDEF", "GHI"))
File "FancyFind.py", line 21, in fancy_find
index = search_within.index(search_for)
ValueError: substring not found
Command exited with non-zero status 1
======
It should print out:
fancy_find("ABCDEF", "DEF") -> "DEF found at index 3!"
fancy_find("ABCDEF", "GHI") -> "GHI was not found within ABCDEF!"
====
where i need help, I can't get help to print:
"GHI was not found within ABCDEF!"
Step by Step Solution
3.46 Rating (146 Votes )
There are 3 Steps involved in it
Step: 1
The issue with your code is that youre trying to access the ind...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started