Apr-09-2020, 02:43 PM
I'm getting the error "int() with base 10" can anyone please find the error
Quote:choclate 35
biscuit 20
Icecream 50
Discount 5
Quote:this is the data in my text file to extract the price i'm using slicing
def calculate(fname):
try:
with open(fname, "r") as file:
totalAmount = 0
FreeItems = 0
Discount = 0
ItemsPurchased = 0
FinalAmount = 0
for line in file.readlines():
line.strip()
ItemsPurchased += 1
if(line[line.find(' ')+1:] != "Free"):
totalAmount += int(line[line.find(' ')+1:])
elif(line[line.find(' ')+1:] == "Free"):
FreeItems += 1
elif(line[line.find("Discount")] == "Discount"):
Discount += int(line[line.find(' ')+1:])
FinalAmount = totalAmount-Discount
except IOError:
print("File doesn't exist cannot perform operations on the file")
else:
print("No of items purchased:".format(ItemsPurchased))
print("No of free items:".format(FreeItems))
print("Amount to pay:".format(totalAmount))
print("Discount given:".format(Discount))
print("Final Amount paid:".format(FinalAmount))
if __name__ == "__main__":
fname = input()
calculate(fname)
