2013-10-10 82 views
-7

我需要的總數來計算......越來越0.00if語句在一個循環中,python3

還需要住宅,商業,城市和教區打印

這是我更新的代碼,

使用「」

if (custType == "R"): 

    custType = Residential 

你需要把信放在引號的原因

print("=========================================================") 

print(format("Name", '<12s'),format("Type", '<15s'),format("Location",'<10s'),format("KwH", '<8s'),format("Total", '>8s')) 

print("=========================================================") 



total = 0 

for i in range(10): 

custName = input() 

custType = input() 

custLoc = input() 

custKwh = eval(input()) 

if (custType == "R"): 

    custType = "Residential" 

if (custType == "B"): 

    custType = "Business" 

    total = (custKwh * 0.05710) + 10 

if (custLoc == "C"): 
    custType = "City" 
    total = (custKwh * 0.0401) + 6 

if (custLoc == "P"): 
    custType = "Parish" 
    total = (custKwh * 0.04411) + 6.60 

print(format(custName, '<12s'),format(custType, '<15s'),format(custLoc, '<10s'),format(custKwh, '<8d'),format(total, '<7.2f'))  
+0

即時通訊從數據文件輸入是R,B,C或P – user2865217

回答

3

嘗試是因爲它的信自己的,沒有引號,代表一個名字就是那個字母的變量。如果你在它周圍加上引號,它的字面意思就是那個字母或單詞。

+0

甜,這似乎有工作,現在我得到錯誤輸入:'總'沒有定義...我如何定義'所以它計算KwH的總成本取決於它的城市,教區還是商業 – user2865217

+1

因爲我不能編輯它......你需要把這封信放在引號中的原因是因爲它上面的信是自己的,不帶引號,代表名稱爲該字母的變量。如果你在它周圍加上引號,它的字面意思就是那個字母或單詞。 – DeadChex

+1

定義像這樣總開始的總權利= 0.0 – Archer