2013-01-16 29 views
2

我用Python創建了這個程序2.7.3 我在我的計算機科學課上做了這個。他分兩部分。對於第一部分,我們必須創建一個計劃來計算五位客戶的每月手機賬單。用戶輸入文本數量,分鐘數量和使用的數據。另外,還有超額費用。超過限制的每GB數據爲10美元,超過限制爲每分鐘0.4美元,每超過限制發送的文本爲0.2美元。 500是文本消息的限制數量,750是限制分鐘數量,2 GB是計劃的限制數據量。如何將已計算的總計放在循環中並將它們相加?

對於作業的第2部分。我必須計算總稅收,總費用(每個客戶賬單加在一起),收取的總政府費用,過度的客戶總數等。

現在我要幫助的是添加客戶賬單。正如我前面所說,當您運行該程序時,它將打印5位客戶的總帳單。我不知道如何將這些單獨的總數分配給一個變量,將它們加在一起,然後最終將它們打印爲一個大變量。

TotalBill = 0  
monthly_charge = 69.99 
data_plan = 30 
minute = 0 
tax = 1.08 
govfees = 9.12 
Finaltext = 0 
Finalminute = 0 
Finaldata = 0 
Finaltax = 0 
TotalCust_ovrtext = 0 
TotalCust_ovrminute = 0 
TotalCust_ovrdata = 0 
TotalCharges = 0 

for i in range (1,6): 
    print "Calculate your cell phone bill for this month" 

    text = input ("Enter texts sent/received ") 

    minute = input ("Enter minute's used ") 

    data = input ("Enter Data used ") 
    if data > 2: 
     data = (data-2)*10 
     TotalCust_ovrdata = TotalCust_ovrdata + 1   
    elif data <=2: 
     data = 0 
    if minute > 750: 
     minute = (minute-750)*.4 
     TotalCust_ovrminute = TotalCust_ovrminute + 1 
    elif minute <=750: 
     minute = 0 
    if text > 500: 
     text = (text-500)*.2 
     TotalCust_ovrtext = TotalCust_ovrtext + 1 
    elif text <=500: 
     text = 0 

    TotalBill = ((monthly_charge + data_plan + text + minute + data) * (tax)) + govfees 
    print ("Your Total Bill is... " + str(round(TotalBill,2))) 





print "The toatal number of Customer's who went over their minute's usage limit is... " ,TotalCust_ovrminute 
print "The total number of Customer's who went over their texting limit is... " ,TotalCust_ovrtext 
print "The total number of Customer's who went over their data limit is... " ,TotalCust_ovrdata 

某些創建的變量未在程序中使用。請忽略它們。

+2

做同樣的事情。在處理每個循環迭代時累積帳單總額的值。 –

+0

@PreetSangha但是如何? (我是菜鳥) –

+0

@PreetSangha我會創建另一個方程式,如「TotalBill」 –

回答

0

正如Preet所建議的。

創建另一個變量一樣TotalBill即

AccumulatedBill = 0 

然後在你的循環放結束。

AccumulatedBill += TotalBill 

這會將每個TotalBill添加到累計。然後在最後打印出結果。

print "Total for all customers is: %s" %(AccumulatedBill) 

注意:對於單詞的第一個字母,變量通常不使用大寫字母。使用camelCase或underscore_separated。

相關問題