2013-10-10 42 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