I am getting "R, B, C, and P" for my outputs when it should be "Residential, Business, City, and Parish"
I am also getting 0.00 for my total, I need the total if its a business, city, or parish (They are all different)...it is not computing.
I am getting my inputs from a .data file and they are correct
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'))
inputs are:
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
1 Answer 1
I would rewrite it as this:
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, custType, custLoc, custKwh = input().split(' ')
custKwh = int(custKwh)
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')
)
The key error here is that you're setting custType again when checking custLoc (copy paste error?)
answered Oct 10, 2013 at 4:53
Randall Hunt
12.7k6 gold badges34 silver badges42 bronze badges
Sign up to request clarification or add additional context in comments.
6 Comments
user2865217
this is still not solving my problem, still getting R,B,C, and P.....and total values are still 0.00. Should I set total = to something else? Why is it not calculating
Randall Hunt
@user2865217 I am not chatting you. Just post your command or learn python on your own -- sorry to be harsh but we do this for free.
Randall Hunt
How are you running the script though? What's the exact command you're using to launch this. How are you getting the data?
user2865217
python pa3.py < pa3.data - all inputs are saved in pa3.data, after each input is a enter
Randall Hunt
what's different between what you're seeing and what I'm seeing? gist.github.com/ranman/6913539
|
lang-py
custLocinstead ofcustTypein your if statements forcustLoc