-3

I'm working with a function that has many different options (contained in "if" and "elif" statements) which all increment or decrement 4 different variables. Once the function ends, I need to unpack the resulting values back to the original variables, so the function can run again. I'm trying to do so with a return command at the end of the function, then a line of code for the unpacking action. I'm receiving a "TypeError: cannot unpack non-interable int object". I am very new at Python and coding in general, so please forgive any obvious errors! How can i eliminate this error? Simplified example code shown below.

a = 200
b = 300
c = 59
d = 9
def command(a, b, c, d):
    blah blah blah
    blah blah blah
    return a, b, c, d
while True:
    a, b, c, d = command(a, b, c, d)
Austin
  • 1

2 Answers2

0

Not sure the logic of the function, assuming it to be simple addition or subtraction to the number itself, and replacing the while condition to 2 iterations. The variables gets unpacked. May be problem in the function logic, if you could share the logic code we can see if there is an issue with that

            a = 200
            b = 300
            c = 59
            d = 9
            i=2
            def command(a, b, c, d):
                a=a+1
                b=b-1
                c=c+1
                d=d-1
                return a, b, c, d
            while i != 0:
                a, b, c, d = command(a, b, c, d)
                i-=1

            print(a,b,c,d)
0

Thanks for all of this feedback! I went back and checked the logic of my functions and did find the error there! One of the branches of my if/then statements did not return the variables needed for the program to later unpack them into the assigned names.

Austin
  • 1