0

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
6
  • First, I don't see how you are getting any outputs since you are not outputting anything. Second, perhaps you should give an example of your inputs after you update your code showing how you output. Commented Oct 10, 2013 at 4:38
  • code updated, this is my whole code.. Commented Oct 10, 2013 at 4:41
  • looks like your input needs you to press enter after every value, it's all getting put in the custName variable. You could fix it by having one input go into all the diff variables with .split(' ') Commented Oct 10, 2013 at 4:46
  • I have it entered after every value in the data file...I didn't want to take up a lot of space so I just entered them that way on here Commented Oct 10, 2013 at 4:48
  • 1
    the other thing you need to do is set custLoc instead of custType in your if statements for custLoc Commented Oct 10, 2013 at 4:49

1 Answer 1

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?)

Sign up to request clarification or add additional context in comments.

6 Comments

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
@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.
How are you running the script though? What's the exact command you're using to launch this. How are you getting the data?
python pa3.py < pa3.data - all inputs are saved in pa3.data, after each input is a enter
what's different between what you're seeing and what I'm seeing? gist.github.com/ranman/6913539
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.