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

    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Outputting Maximum and Minimum Values


    The expected results:

    2012 vs. 1980s
    March coverage fraction 0.969491525424
    September coverage fraction 0.476319350474
    2012 vs. 1990s
    March coverage fraction 0.990990990991
    September coverage fraction 0.527736131934
    2012 vs. 2000s
    March coverage fraction 1.01203113942
    September coverage fraction 0.628571428571
    Max winter coverage loss 0.969491525424
    Max summer coverage loss 0.476319350474


    What I get:
    2012 vs. 2000s
    March coverage fraction 0.969491525424
    2012 vs. 1990s
    March coverage fraction 0.990990990991
    2012 vs. 2000s
    March coverage fraction 1.01203113942
    Max winter coverage loss 0.969491525424


    Question:
    Using only one function with four parameters, how can I get the September print statements right after the March statements?
    My original idea was to call the function again with the parameters (s1980, s1990, s2000, s2012) but that gave me the wrong results!


    My code:

    Code:
    #!/usr/bin/python3
    
    m1980 = 14.75
    m1990 = 14.43
    m2000 = 14.13
    m2012 = 14.30
    
    s1980 = 7.39
    s1990 = 6.67
    s2000 = 5.60
    s2012 = 3.52
    
    def march_frac_years(w, x, y, z):
    
            print '2012 vs. 2000s'
            m2012_1980 = z/w
            print '  March coverage fraction ' + str(m2012_1980)
    
            print '2012 vs. 1990s'
            m2012_1990 = z/x
            print '  March coverage fraction ' + str(m2012_1990)
    
            print '2012 vs. 2000s'
            m2012_2000 = z/y
            print '  March coverage fraction ' + str(m2012_2000)
    
            max_winter = min(m2012_1980, m2012_1990, m2012_2000)
            print 'Max winter coverage loss ' + str(max_winter)
    
    march_frac_years(m1980, m1990, m2000, m2012)
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    479
    Rep Power
    33
    One way, and it requires some tweaking yet
    Code:
    def frac_years(numer, denom, ctr, month):
        if ctr < 3:
            result = numer/denom
            print '  %s coverage fraction %f' % (month, result)
            return result
    
        if 3 == ctr:
            max_winter = min(numer, denom, month)
            print 'Minimum winter coverage loss ' + str(max_winter)
    
    lits_list = ['2012 vs. 1980s', '2012 vs. 1990s', '2012 vs. 2000s']
    march = [14.75, 14.43, 14.13, 14.30]
    sep = [7.39, 6.67, 5.60, 3.52]
    march_results=[]
    sep_results=[]
    for ctr in range(3):
        print lits_list[ctr]
        result=frac_years(march[ctr], march[3], ctr, "March")
        march_results.append(result)
        result=frac_years(sep[ctr], sep[3], ctr, "September")
        sep_results.append(result)
        print
    frac_years(march_results[0], march_results[1], 3, march_results[2])
    frac_years(sep_results[0], sep_results[1], 3, sep_results[2])
    Last edited by dwblas; February 8th, 2013 at 10:12 AM.

IMN logo majestic logo threadwatch logo seochat tools logo