In: Computer Science
Python pls
1. The function only allow having one return statement. Any other statements are not allowed. You only have to have exactly one return statement.
For example
the answer should be
def hello(thatman):
return thatman * thatman
Create a function search_hobby. This function returns a set of hobby names and people's excitement level.
input
database = {'Dio': {'Lottery': 2, 'Chess': 4, 'Game': 3},'Baily': {'Game': 2, 'Tube': 1, 'Chess': 3}, 'Chico': {'Punch': 2, 'Chess': 5}, 'Aaron': {'Chess': 4, 'Tube': 2, 'Baseball': 1}}
def search_hobby(database, num):
#ONLY ONE STATEMENT IS ALLOWED (RETURN STATEMENT)
search_hobby(database,0) -> {'Chess', 'Punch', 'Baseball', 'Game', 'Tube', 'Lottery'}
search_hobby(databalse,3) - > {'Chess', 'Game'}
If you have any queries please comment in the comments section I will surely help you out and if you found this solution to be helpful kindly upvote.
Solution :
Code:
# function search hobby to return the set of hobbies using only
1 statement
def search_hobby(database,excitement_level):
# return the set of list of those hobbies whose exitement level is
greater than or equal to the given exitement level
return set([element[0] for item in database.values() for element in
item.items() if element[1]>=excitement_level])
# declare the database dictionary
database = {
'Dio': {'Lottery': 2, 'Chess': 4, 'Game': 3},
'Baily': {'Game': 2, 'Tube': 1, 'Chess': 3},
'Chico': {'Punch': 2, 'Chess': 5},
'Aaron': {'Chess': 4, 'Tube': 2, 'Baseball': 1}
}
# call the function
print(search_hobby(database,3))
Output :