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. (ONE STATEMENT ALLOWED)
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'}
def search_hobby(database, hobby):
return({j for i in database.values() for j, s in i.items() if s == hobby} if hobby>0 else {j for i in database.values() for j, s in i.items() if s > hobby})
___________________________________________________________________
>>> print(search_hobby(database,3))
{'Game', 'Chess'}
>>> print(search_hobby(database,5))
{'Chess'}
>>> print(search_hobby(database,0))
{'Game', 'Chess', 'Punch', 'Tube', 'Lottery', 'Baseball'}
>>> print(search_hobby(database,2))
{'Lottery', 'Game', 'Punch', 'Tube'}
___________________________________________________________________
Note: If you have
queries or confusion regarding this question, please leave a
comment. I would be happy to help you. If you find it to be useful,
please upvote.