Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
December 7th, 2012, 04:40 PM
 roydorsthorst
Registered User

Join Date: Dec 2012
Posts: 2
Time spent in forums: 16 m 40 sec
Reputation 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)

#2
December 7th, 2012, 08:53 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,117
Time spent in forums: 1 Month 3 Weeks 2 Days 3 h 10 m 4 sec
Reputation Power: 455
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!

#3
December 8th, 2012, 06:06 AM
 roydorsthorst
Registered User

Join Date: Dec 2012
Posts: 2
Time spent in forums: 16 m 40 sec
Reputation Power: 0
thanks, worked out!

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > Max value in for loop