use the python language and fix the error code
#Write a function called rabbit_hole. rabbit_hole should
have
#two parameters: a dictionary and a string. The string may be
#a key to the dictionary. The value associated with that key,
#in turn, may be another key to the dictionary.
#
#Keep looking up the keys until you reach a key that has no
#associated value. Then, return that key.
#
#For example, imagine if you had the following dictionary.
#This one is sorted to make this example easier to follow:
#
# d = {"bat": "pig", "pig": "cat", "cat": "dog", "dog":
"ant",
# "cow": "bee", "bee": "elk", "elk": "fly", "ewe": "cod",
# "cod": "hen", "hog": "fox", "fox": "jay", "jay": "doe",
# "rat": "ram", "ram": "rat"}
#
#If we called rabbit_hole(d, "bat"), then our code should...
#
# - Look up "bat", and find "pig"
# - Look up "pig", and find "cat"
# - Look up "cat", and find "dog"
# - Look up "dog", and find "ant"
# - Look up "ant", and find no associated value, and so it
would
# return "ant".
#
#Other possible results are:
#
# rabbit_hole(d, "bat") -> "fly"
# rabbit_hole(d, "ewe") -> "hen"
# rabbit_hole(d, "jay") -> "doe"
# rabbit_hole(d, "yak") -> "yak"
#
#Notice that if the initial string passed in is not a key in
#the dictionary, that string should be returned as the result
as
#well.
#
#Note, however, that it is possible to get into a loop. In
the
#dictionary above, rabbit_hole(d, "rat") would infinitely go
#around between "rat" and "ram". You should prevent this: if
a
#key is ever accessed more than once (meaning a loop has been
#reached), return the boolean False.
#
#Hint: If you try to access a value from a dictionary that
does
#not exist, a KeyError will be raised.
#Write your function here!
def rabbit_hole(d,word):
for key in d.keys():
if word == key:
new_key = d[word]
word = new_key
continue
elif word != key:
pass
return d[word]
#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: ant, hen, doe, yak, False, each on their own line.
d = {"bat": "pig", "pig": "cat", "cat": "dog", "dog": "ant",
"cow": "bee", "bee": "elk", "elk": "fly", "ewe": "cod",
"cod": "hen", "hog": "fox", "fox": "jay", "jay": "doe",
"rat": "ram", "ram": "rat"}
print(rabbit_hole(d, "bat"))
print(rabbit_hole(d, "ewe"))
print(rabbit_hole(d, "jay"))
print(rabbit_hole(d, "yak"))
print(rabbit_hole(d, "rat"))
In: Computer Science
What is the purpose and use of personal financial statements and budgets for successful financial planning and wealth management?500-800 word IN DEPTH ANSWER PLEASE. REFERENCES SOURCES PLEASE
In: Finance
What is the purpose and use of personal financial statements and budgets for successful financial planning and wealth management?500-800 word IN DEPTH ANSWER PLEASE. REFERENCES SOURCES PLEASE
In: Finance
what do you see as the economic impact of the COVID-19
relief checks? how do you figure to the idea of transfer
payments?
(a 200 word response is ideal)
In: Economics
Minimum of a 500-word personal essay that demonstrates a life-changing event the applicant has overcome and why he/she has chosen to pursue a career in healthcare (nursing)
In: Nursing
Q: Draw a UAE knowledge economy roadmap in line with vision 2021.
Note: answers should be in Details and in your own Words - the answers should be typed in a word version
In: Economics
|
In: Accounting
In: Economics
To what extent is an unequal distribution of income and wealth a
positive or a normative problem? Evaluate the different methods to
re-distribute income and wealth in a country.
Word Limit: 700 words
In: Economics
Please describe the financial requirements regarding stock and other finances of the acquisition of YouTube by Google in 2006.
Please answer with a 1000 word typed response. Please cite sources.
In: Finance