TypeError Help: cannot unpack non-iterable int object

 ```python
    import random

def main():
    num1,num2,num3 = get_random()
    user_answer, random_choice = display_problem(num1,num2,num3)
    get_feedback(user_answer, random_choice, num1, num2, num3)
    
def get_random():
    num1 = random.randint(0,999)
    num2 = random.randint(0,999)
    num3 = random.randint(0,999)
    print("Numbers: ",num1,num2,num3)
    return num1,num2,num3

def display_problem(num1,num2,num3):
    random_choice = random.randint(0,10)
    if random_choice > 5:
        print(f"What is the answer to sqrt({num1} * {num2}) - min({num1}, {num2}, {num3})")
        user_answer = int(input("\nEnter answer: "))
        return user_answer
    elif random_choice < 5:
        print(f"What is the answer to max({num1},{num2},{num3}) + sqrt({num2} * {num3})")
        user_answer = int(input("\nEnter answer: "))
        return user_answer, random_choice


def get_feedback(user_answer, random_choice, num1, num2, num3):
    if random_choice > 5:
        answer = (sqrt((num1 * num2)) - min(num1,num2,num3))
        if(user_answer == answer):
            print("Your answer is correct!")
        else:
            print("Your answer is not correct.")
    elif random_choice < 5:
        answer = (max(num1,num2,num3)+sqrt(num2*num3))
        if(user_answer == answer):
            print("Your answer is correct!")
        else:
            print("Your answer is not correct.")
                  
main()
    ```

when running the code and answering a question I receive an error stating the sqrt has not been defined (which is confusing as it is a python base function)// and I receive a type error line 5, in main
user_answer, random_choice = display_problem(num1,num2,num3)
TypeError: cannot unpack non-iterable int object

If In Doubt, Print It Out.

Have a look at the line that’s giving you problems. Modify it to print out what you’re seeing. Especially, shice this only happens sometimes, try running the program more than once and see if you have different kinds of output. (HINT: Your display_problem function can return in three different ways.)

With the sqrt function, look in the documentation; where is it defined? How do you access it?

As a side point, the square root of a randomly selected number between 0 and 1000 is highly unlikely to be an integer. So users are doomed to usually be incorrect, the way the program is written.

1 Like

Ah thank you, I realized I made a stupid error in the passing of variables back to the main and fixed it rather easily, and for the sqrt error, I imported math and changed the sqrt to math.sqrt and everything works now!

Cool! Now while you’re testing it, see if you can find the third way that display_problem() can return, which will most likely give you back the same unpacking error. It might surprise you if you haven’t thought too much about your logic :slight_smile: Hint: Try to figure out the precise chances of the different if branches happening.