有没有更好的方法用python编写代码
第一个改进应该是for循环有没有更好的方法用python编写代码,python,sorting,rows,Python,Sorting,Rows,第一个改进应该是for循环 #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
#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]
第一个改进应该是for循环
#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]
你是在问如何缩短这个函数吗?对其内部的循环使用
。从未听说过循环吗-/哦,我的上帝。使用你的程序员能力,循环是这些能力的基础。还可以使用像pycharm这样的IDE,这将有助于简化生活;这是我第一次使用python,谢谢你的评论。你是在问如何缩短函数吗?对其内部的
循环使用。从未听说过循环吗-/哦,我的上帝。使用你的程序员能力,循环是这些能力的基础。还可以使用像pycharm这样的IDE,这将有助于简化生活;这是我第一次玩python,谢谢你的评论。谢谢你,我会试试的。这是我第一次在python中胡闹。谢谢!!!!这就像一个魅力,我将不得不研究如何使用for循环。谢谢,我会试试的。这是我第一次在python中胡闹。谢谢!!!!这就像一个魅力,我将不得不研究如何使用for循环。
#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]