| | |
return value None
Thread Solved |
•
•
Join Date: Feb 2008
Posts: 1
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Dec 2006
Posts: 1,008
Reputation:
Solved Threads: 285
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.
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.
![]() |
Similar Threads
- Return Array from C++ (C++)
- problem with VAT and return copmbo box (Visual Basic 4 / 5 / 6)
- Return Length of a string? (C++)
Other Threads in the Python Forum
- Previous Thread: Compress Files with Zip (Python)
- Next Thread: calling a function without changing scope
| Thread Tools | Search this Thread |
accessdenied advanced apache application argv array beginner book change command converter countpasswordentry csv curved dan08 def dictionary dynamic edit enter event examples file float format function google gui homework import inches input jaunty java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric obexftp output parameters parsing path phonebook plugin port prime programming projects py2exe pygame pygtk pyopengl python random recursion redirect remote return reverse scrolledtext session simple skinning software sprite statictext string strings syntax terminal text threading time tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable voip wordgame wxpython






