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 February 7th, 2013, 05:01 PM
laffytaffykidd laffytaffykidd is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 2 laffytaffykidd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 12 sec
Reputation 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)

Reply With Quote
  #2  
Old February 8th, 2013, 10:09 AM
dwblas dwblas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 294 dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 18 h 53 m 55 sec
Reputation Power: 7
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Outputting Maximum and Minimum Values

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