return value None

Thread Solved

Join Date: Feb 2008
Posts: 1
Reputation: roelandt is an unknown quantity at this point 
Solved Threads: 0
roelandt roelandt is offline Offline
Newbie Poster

return value None

 
0
  #1
Feb 19th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,009
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 929
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: return value None

 
0
  #2
Feb 20th, 2008
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.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,008
Reputation: woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough 
Solved Threads: 285
woooee woooee is offline Offline
Veteran Poster

Re: return value None

 
0
  #3
Feb 20th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC