Hi
I'm new in python and i'm do not understand why my code is not working. I want to generated random figures with this code:

import random
import division


a1 = ''
a2 = ''
def zufallsZahl(a1,a2):
a1 = random.randint(1,10)
a2 = random.randint(1,10)
print a1, a2
s1 = [a1, a2]

while a1 % a2 == 0:
print 'Wert von a1 und a2: ', a1,a2
s1 = [a1, a2]
print 'Wert von s1: ', s1
return s1

else:
print 'Ich bin im else'
zufallsZahl(0,0)

and now i am want request it with the following code:

import zufallsZahl
import rechnenCore

s1 = zufallsZahl.zufallsZahl()


#b = zufallsZahl.zufallsZahl()
#rechnenCore.rechnen(a,b)
print s1

My problem is that sometimes the retur value is None and sometimes the correct figures.

Can anybody help? Thanks
Roel

Please use the [code=python] and [/code] tag pair to enclose your python code. Without this the code becomes very difficult to read, since all indentations are lost.

As stated previously, it is difficult to tell without code tags (use the "#" in the icon list). One problem is the two lines below: one is the function definition and the other is the calling line of that function. It is unlikely that this is the problem however. It also looks like the while loop can be an infinite loop if a1 % a2 ==0, since those values are not changed, unless the return statement exits the loop. If that is the case, then when a1 % a2 != 0 there is no value returned=None.
def zufallsZahl(a1,a2):
s1 = zufallsZahl.zufallsZahl()

It should be
def zufallsZahl(a1,a2):
s1 = zufallsZahl.zufallsZahl(b,c)

or (probably this)
def zufallsZahl():
s1 = zufallsZahl.zufallsZahl()

HTH. If not post back using code tags.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.