user3123757
user3123757

Reputation: 19

Need Some Help on Python Code

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

Upvotes: 1

Views: 112

Answers (1)

shivang98
shivang98

Reputation: 21

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.

Upvotes: 2

Related Questions