简体   繁体   中英

Assistance with missing required positional arguments

def computeValue(condition , gps , wifi , camera):
    int(val1=0)
    int(val2=0)

    val1 = (condition + gps + wifi + camera)
    val2 = (condition + gps + wifi + camera)
    return val1
    return val2

def main():

    w=0;
    x=0;
    y=0;
    z=0;
    q=0;
    r=0;
    s=0;
    t=0;
# it then has conditions to assign values to wxyzqrst, and then

    val1 = computeValue(w+x+y+z)
    val2 = computeValue(q+r+s+t)
main()

error: TypeError: computeValue() missing 3 required positional arguments: 'gps', 'wifi', and 'camera'

Anyone have any idea as to what Im doing wrong?

Yu;

wwii, is right - a tutorial would do you great service as this is pretty foundational to programming so you are going to have a long road to travel if you don't take some time and learn the fundamentals.

However, in general, think of a function (computeValue in your case), as a mathematical algorithm. Imagine instead it was to compute the area of a rectangle. You would say Area = F(x,y) = x * y. From this you could say F(1,2)=2, F(2,2) = 4, F(4,3)= 12, and so on. But you couldn't say F(3*4) - that wouldn't make sense as it would mean the same as F(12). Your algorithm definition requires two arguments, not one.

Now - extend that to your computeValue function. You define it as requiring 4 arguments (aka parameters). However, you are trying to call it using "w+x+y+z". Python is going to be smart enough to add those values before calling the function. Much like F(12) above, you are only giving a single argument (or parameter). You need for values separated by a comma, such as computeValue(w,x,y,z)

Thats problem #1. Your next problem is that you can't return twice from a function (val1 and val2). You can return a list, array, tuple, etc. from a function and use each part but I think that will complicate things beyond what you are ready for at this point. For now, if you want two different calculations, just make two functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM