-8

我需要计算总数...得到 0.00

还需要住宅、商业、城市和教区打印

这是我更新的代码,

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'))     
4

1 回答 1

3

尝试使用“”

if (custType == "R"):

    custType = Residential

您需要将字母放在引号中的原因是因为该字母本身,没有引号,代表一个名称为该字母的变量。如果你在它周围加上引号,它的字面意思是那个字母或单词。

于 2013-10-10T02:41:02.857 回答