我得到「R,B,C和P」爲我的輸出時,它應該是「住宅,商業,城市和教區」Python3 if語句在循環
我也越來越0.00我總的來說,如果它的業務,城市或教區(他們都不同),我需要總數......這不是計算。
我從.data文件讓我的投入,他們是正確的
print("=========================================================")
print(format("Name", '<12s'),format("Type", '<15s'),format("Location", '<10s'),format("KwH", '>6s'),format("Total", '>10s'))
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"):
custLoc = "City"
total = (custKwh * 0.0401) + 6
if (custLoc == "P"):
custLoc = "Parish"
total = (custKwh * 0.04411) + 6.60
print(format(custName, '<12s'),format(custType, '<15s'),format(custLoc, '<10s'),format(custKwh, '>6d'),format(total, '>10.2f'))
輸入是:
Smith R P 4500 Taylor R C 6000 Williams B C 10500 Johnson R C 7500 Davis R P 3000 Woods B P 25300 Morgan R C 5800 Landry R C 3900 Young B P 18500 Wilson R P 7000
首先,我不明白你是如何得到任何輸出,因爲你不輸出任何東西。其次,也許你應該在更新代碼後顯示你的輸入例子。 – sberry
代碼已更新,這是我的整個代碼。 – user2865217
看起來像您的輸入需要您在每個值之後按enter鍵,它都會放入custName變量中。你可以通過使用.split('') – ranman