pythonfunctionmultiple-arguments

Multiple arguments in Python function


The code I have is works for one argument. But I am trying to pass through multiple arguments at a time.

def day(x):
    mydict = { 2.4:104.2 , 5:109.2, 5.5:112.2, 2.1:110.2, 5.7:114}
    keylist=sorted(mydict.keys())

    if x in mydict:
        return mydict[x]

    elif x> max(mydict.keys()):
        return mydict[max(mydict.keys())]

    elif x< min(mydict.keys()):
        return 'NaN'

    else:
        y=len(keylist)-1
        for i in keylist:
            if x>keylist[y]:
                return mydict[keylist[y]]
            else:
                y=y-1

The code I tried for the multiple arguments used

def day(*z):

for x in z:
 #rest of code
continue

how ever this only seemed to return one answer, that being the first value from the list z. Where am I going wrong?

Thanks


Solution

  • You want to return one value for each element on te iterable ? Try to use yield instead of return.