2017-04-20 31 views
0
#The function displayInfo will display the savings, 
#the costs prior to going green, the costs after 
#going green for the appropriate months 

def displayInfo (notGreenCosts, goneGreenCosts, savings, months): 
    print 
    print '\t' '\t' '\t' 'SAVINGS' 
    print '___________________________________________________________' 
    print 'SAVINGS' '\t''\t' 'NOT GREEN' '\t' 'GONE GREEN' '\t' 'MONTH' 
    print '-----------------------------------------------------------' 
    print '$',savings[0], '\t','\t', '$',notGreenCosts[0], '\t','\t', '$',goneGreenCosts[0], '\t','\t', months[0] 
    print '$',savings[1], '\t','\t', '$',notGreenCosts[1], '\t','\t', '$',goneGreenCosts[1], '\t','\t', months[1] 
    print '$',savings[2], '\t','\t', '$',notGreenCosts[2], '\t','\t', '$',goneGreenCosts[2], '\t','\t', months[2] 
    print '$',savings[3], '\t','\t', '$',notGreenCosts[3], '\t','\t', '$',goneGreenCosts[3], '\t','\t', months[3] 
    print '$',savings[4], '\t','\t', '$',notGreenCosts[4], '\t','\t', '$',goneGreenCosts[4], '\t','\t', months[4] 
    print '$',savings[5], '\t','\t', '$',notGreenCosts[5], '\t','\t', '$',goneGreenCosts[5], '\t','\t', months[5] 
    print '$',savings[6], '\t','\t', '$',notGreenCosts[6], '\t','\t', '$',goneGreenCosts[6], '\t','\t', months[6] 
    print '$',savings[7], '\t','\t', '$',notGreenCosts[7], '\t','\t', '$',goneGreenCosts[7], '\t','\t', months[7] 
    print '$',savings[8], '\t','\t', '$',notGreenCosts[8], '\t','\t', '$',goneGreenCosts[8], '\t','\t', months[8] 
    print '$',savings[9], '\t','\t', '$',notGreenCosts[9], '\t','\t', '$',goneGreenCosts[9], '\t','\t', months[9] 
    print '$',savings[10], '\t','\t', '$',notGreenCosts[10], '\t','\t', '$',goneGreenCosts[10], '\t','\t', months[10] 
    print '$',savings[11], '\t','\t', '$',notGreenCosts[11], '\t','\t', '$',goneGreenCosts[11], '\t','\t', months[11] 
+0

你問如何縮短funcion?在裏面使用'for'循環。 – freakish

+0

從來沒有聽說過循環? : -/ –

+0

哦,我的上帝。使用你的程序員權力,循環是這些的基礎。還可以使用像pycharm這樣的IDE,它會讓生活更輕鬆。 ; P – answerSeeker

回答

4

第一次改進應該是for-loop。

for i in range(12): 
    print '$',savings[i], '\t','\t', '$',notGreenCosts[i], '\t','\t', '$',goneGreenCosts[i], '\t','\t', months[i] 
+0

謝謝,我會嘗試。這是我第一次搞蟒蛇。 – Lawrence

+0

謝謝!!!!這就像一個魅力,我將不得不研究如何使用for循環。 – Lawrence

0
#The function displayInfo will display the savings, 
#the costs prior to going green, the costs after 
#going green for the appropriate months 

def displayInfo (notGreenCosts, goneGreenCosts, savings, months): 
    print 
    print '\t' '\t' '\t' 'SAVINGS' 
    print '___________________________________________________________' 
    print 'SAVINGS' '\t''\t' 'NOT GREEN' '\t' 'GONE GREEN' '\t' 'MONTH' 
    print '-----------------------------------------------------------' 
    for i in range(12): 
     print '$',savings[i], '\t','\t', '$',notGreenCosts[i], '\t','\t', '$',goneGreenCosts[i], '\t','\t', months[i] 
相關問題