I am new to python3. I have some requirement like this:
function : predictRisk
Parameters :
1 :
positional / keyword
type dicitionary
Note : return value of function prepareData
2 :
Risk Zones
Type : lists
returns riskiness of that person based on the places s/he has visited. If a person has visited a place which is identified to be in risk zones, then the person should be quarantined for at least 14 days.
So,I tried like this:
def predictRisk(**k):
x = k['visited']
print(x)
riskzones = ['kapan', 'chabail', 'newroad']
for i in riskzones:
for k,v in x:
if v == i:
return 'You are in danger zone'
else:
return 'You are not in danger zone'
for 2nd parameter I need to pass list,so I tried, xyz list didnot worked here and i removed this way.
def predictRisk(**k,xyz=[]):
x = k['visited']
print(x)
riskzones = ['kapan', 'chabail', 'newroad']
for i in riskzones:
for k,v in x:
if v == i:
return 'You are in danger zone'
else:
return 'You are not in danger zone'
So,I tried as:
k=prepareData('arun','nepali',location1='chabail',location2='kathmandu')
print(k)
predictRisk(**k)
But,I got error as:
{'name': 'arun', 'national': 'nepali', 'visited': [{'location1': 'chabail'}, {'location2': 'kathmandu'}]}
[{'location1': 'chabail'}, {'location2': 'kathmandu'}]
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-119-fabcf7206f8b> in <module>
2 print(k)
3
----> 4 predictRisk(**k)
<ipython-input-117-82fada056b90> in predictRisk(**k)
4 riskzones = ['kapan', 'chabail', 'newroad']
5 for i in riskzones:
----> 6 for k,v in x:
7 if v == i:
8 return 'You are in danger zone'
ValueError: not enough values to unpack (expected 2, got 1)
Why is this error coming?I searched for the answers but couldnot found the proper answer.Is it also possible riskzones = ['kapan', 'chabail', 'newroad'] that i can pass list as argument when calling predictRisk()?
xis a dict then tryx.items(){k: v for d in x for k, v in d.items()}