#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Max value in for loop [SOLVED]


    So i want to know the highest value in the 'for' loop listed below, but it doesnt work :s notes are added in code
    Code:
    import math
    def main():
        global r,n
        n = int(input('Name the amount of individuals: '))
        r = int(input('Name the amount of recombinant children: '))
        print('')
        bereken()
        
    def bereken():
        global LOD
        for x in range(1,51,1):         
            z = x/100
            LOD = math.log10 (((1-z)**(n-r)*(z**r))/(0.5**n))
            print('At a recombinant fraction of ',float(z))
            print('The maximum LOD-value is: ',float(LOD))
            print('')
            MAX()
    
    def MAX():
        print('The highest LOD-value is: ',max(LOD))   
    
    main() 
    
    #the LOD is 0.0 becouse x=50 (the sum equals 0)
    #and in the loop LOD is overwritten each time (50 times total)
    #which means its not a list please help!
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,900
    Rep Power
    481
    You're using python version 3?
    Code:
    def bereken():
        LOD = list()
        for x in range(1,51,1):         
            z = x/100.0
            LOD.append(math.log10 (((1-z)**(n-r)*(z**r))/(0.5**n)))
            print('At a recombinant fraction of ',z)
            print('The maximum LOD-value is: ',LOD[-1])
            print('')
        MAX(LOD)
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0
    thanks, worked out!

IMN logo majestic logo threadwatch logo seochat tools logo