I'm writing a simple maths sketch. At this point I want to check if 2 random numbers, when divided, leave a quotient. If not then pass them onto the next part of the program. If the quotient is not 0 then go back and pick new numbers. The code works perfectly if the 2 numbers return a quotient of 0 first time through. The numbers are sent to the next function using return. If the numbers don't give a 0 quotient, the code picks 2 new numbers and rechecks. However, when the new numbers fulfill the criteria and are sent on, they are rejected with " cannot unpack non-iterable NoneType object". This has been sent by the same command that works if the numbers fulfill the criteria FIRST TIME!!
def gen(): import random #imports the random number generator rand1 = random.randint(1,100) rand2 = random.randint(1,10) return rand1, rand2 def source(): rand1,rand2=gen() ans = rand1/rand2 print (rand1,rand2,ans)# to check the random numbers come through if rand1%rand2!=0: source() elif rand1%rand2==0: nos=(rand1,rand2) return nos def receiver(): nos = source() print (nos[0]) print (nos[1])
sourcein theifstatement, didn't change the value ofrand1,rand2, you need to assign them again. Only to you understand, to your code work, you need to replace that line withrand1,rand2=source().