this is python program and i am getting error at \"elif\" i dont know what to do
ID: 3813382 • Letter: T
Question
this is python program and i am getting error at "elif" i dont know what to do
this program not running
#file name :
#User :
#Date :
#this is the program that calculates the amount of oil remaining in a tank.
fill_count = 0;
takeout_count = 0;
capacity = input("capacity of the tank: ");
print ("capacity");
user = input("enter number of gallons of oil in the tank : ");
count = user;
while(count<=capacity):
while(count!=0 or count!="no more"):
amount= capacity-count;
action = input("(0)quit (1)finlling oil (2)taking out ");
if(action==1):
add_amount = input("enter the gallons for oil filling: ")
if(add_amount<=amount):
count += add_amount;
fill_count += 1;
print "number of oil fillups :"+ str(fill_count);
print "number of oil drawouts :"+ str(takeout_count);
print "oil balance :"+ str(count);
else:
print("capacity of tank exceeded.");
break
elif action is 0:
take_amount = input("enter the gallons to draw oil : ");
if(take_amount<=count):
count -=take_amount;
takeout_count += 1;
print ("number of oil fillups :") + str(fill_count)
print ("number of oil drawouts :") + str(takeout_count);
print ("oil balance :") + str(count);
else:
print("limited oil in the tank.")
break;
else:
Explanation / Answer
there was two bugs in your code
1. identation problem : youh have not idented elif(action==0) exactly below if(action==1)
2. type error: when you received a string as an input which is apparantly an ineteger i.e capacity,count etc ,you did not converted them to int using int() funtion.
----------------------------------------
#file name :
#User :
#Date :
#this is the program that calculates the amount of oil remaining in a tank.
fill_count = 0;
takeout_count = 0;
capacity = int(input("capacity of the tank: "));
print ("capacity");
user = input("enter number of gallons of oil in the tank : ");
count = int(user);
while(count<=capacity):
while(count!=0 ):
amount= int(capacity-count);
action = int(input("(0)quit (1)finlling oil (2)taking out "));
if(action==1):
add_amount = int(input("enter the gallons for oil filling: "));
if(add_amount<=amount):
count += add_amount;
fill_count += 1;
print "number of oil fillups :"+ str(fill_count);
print "number of oil drawouts :"+ str(takeout_count);
print "oil balance :"+ str(count);
else:
print("capacity of tank exceeded.");
break
elif action == 0:
take_amount = input("enter the gallons to draw oil : ");
if(take_amount<=count):
count -=take_amount;
takeout_count += 1;
print ("number of oil fillups :") + str(fill_count)
print ("number of oil drawouts :") + str(takeout_count);
print ("oil balance :") + str(count);
else:
print("limited oil in the tank.")
break;
else:print("yet my code is incomplete");
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.