-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path56.py
39 lines (33 loc) · 1.32 KB
/
56.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#Write a 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 your function here!
def fancy_find(search_within, search_for):
if search_for in search_within:
num = search_within.find(search_for)
return(search_for + " found at index " + str(num) + "!")
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"))