我需要计算总数...得到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'))
答案 0 :(得分:3)
尝试使用“”
if (custType == "R"):
custType = Residential
你需要把这个字母放在引号中的原因是因为它上面的字母没有引号代表一个名字就是那个字母的变量。如果你在它周围加上引号,它的字面意思是字母或单词。