Killjoy269
Killjoy269

Reputation: 11

Finding the Max Term in a loop without if

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

Upvotes: 1

Views: 183

Answers (1)

Dean Elbaz
Dean Elbaz

Reputation: 2450

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

Upvotes: 2

Related Questions