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

print 'Ich bin im else'

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

import zufallsZahl
import rechnenCore

s1 = zufallsZahl.zufallsZahl()

#b = zufallsZahl.zufallsZahl()
print s1

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

Can anybody help? Thanks

10 Years
Discussion Span
Last Post by woooee

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.