Take the 2-minute tour ×

I looked and could not find the answer to my question so here it is. I have written a loop that outputs a power rating for different frequencys. The largest power rating is somewhere in the middle of the loop output. I need to indicate which is the largest by printing max next to it. However I have been limited and am not allowed to use an if condition. How would I go about getting my program to determine the largest output and mark it with text? I am using python.

while frQncy < 24.0:                                                             
    TERAHZ_TO_HZ = frQncy * 10.0**12                                              
    v_ = TERAHZ_TO_HZ                                                                 
    I_ = ((2.0 * h_ * v_**3) / (c_**2)) * (1.0/(math.exp((h_ * v_) / (k_ * Tk))-1.0))   
    print "Frequency: %.3g Spectral Radiance: %.4E" % (frQncy, I_)                       
    frQncy += 0.2
share|improve this question
Why are you limited against using an IF statement? Seems an unusual situation. –  Lewis Harvey Oct 2 '12 at 15:29
to add challenge to the problem. It is an intro class that has not dealt with IF statements yet so we were limited to using only what has been covered so far. –  Killjoy269 Oct 2 '12 at 15:31
Fake it with a one iteration while loop? ;D –  Wug Oct 2 '12 at 15:31
max_val = max(new_val,max_val) ... maybe useful ... –  Joran Beasley Oct 2 '12 at 15:31
Teaching while before if seems backwards to me, but oh well. Joran's suggestion sounds right: there's a max() function that you can use. –  dyoo Oct 2 '12 at 15:39
show 2 more comments

1 Answer

You could put all the frequencies in an iterable and use the built in max() function

share|improve this answer
add comment

Your Answer


