1

This is My Python Code For Calculating Electricity Bill

cust=input("Enter Customer Number\n");
units=input("Enter No of Units\n");

if(units<200&units>0):
        bill=0.50*units;

elif(units>200&units<400):
        bill=100+(0.65*(units-200))
        print"\n in Loop2\n"

elif(units>400&units<600):
       bill=230+(0.80*(units-400))
       print"\n in Loop3\n"

print"Bill For Customer Number ",cust," is ",bill

if I give units as 200+ it is in Loop 2 But if I Give units as 430 it is still running in Loop2

I am New To python so need some help

3
  • 1
    You can use this syntax : if 0<units<200: ... Commented Oct 14, 2017 at 15:18
  • thank you PRMoureu Commented Oct 14, 2017 at 15:21
  • Please try to find a question title that's descriptive and specific to the question, so if someone else had already asked it before you could recognize it (and not need to ask again) just from the title. If every question is just "need some help", there's no way to tell if anyone else has asked the same one. Commented Oct 14, 2017 at 17:14

1 Answer 1

2
cust=input("Enter Customer Number\n");
units=input("Enter No of Units\n");

 if(units<200 and units>0):
    bill=0.50*units

 elif(units>200 and units<400):
    bill=100+(0.65*(units-200))
    print"\n in Loop2\n"

 elif(units>400 and units<600):
   bill=230+(0.80*(units-400))
   print"\n in Loop3\n"

 print"Bill For Customer Number ",cust," is ",bill

Use "and" in place of "&". Boolean operators are usually used on boolean values but bitwise operators are usually used on integer values. "and" tests whether both expressions are logically True while "&" (when used with True/False values) tests if both are True.

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

Comments

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.