Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 7th, 2012, 03:40 PM
roydorsthorst roydorsthorst is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 roydorsthorst User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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)
#which means its not a list please help!

Reply With Quote
  #2  
Old December 7th, 2012, 07:53 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,390 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 14 h 48 m 54 sec
Reputation Power: 383
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!

Reply With Quote
  #3  
Old December 8th, 2012, 05:06 AM
roydorsthorst roydorsthorst is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 roydorsthorst User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 40 sec
Reputation Power: 0
thanks, worked out!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Max value in for loop

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap