I am writing a code to practice. I am learning lists in python, and I decided to use it through grocery buying. Basically I will input the numbers in the list by calling the function in console, and those numbers will add up and the tax of the total after adding them, and the output should be the total.
The problem is there is something wrong in my math or somewhere where the output is coming incorrect.
def taxes(num):
if num >= 0 and num <10:
num = (num + num*0.07)
return num
elif num >=10 and num <=19:
num = (num + num*0.10)
return num
elif num >=20:
num = (num + num*0.15)
return num
def list_grocery(lst):
#new_list = []
total = 0
for ele in range(0, len(lst)):
total = taxes(total + lst[ele])
return total
For example
when I call list_grocery([1,2,3,4,4,7])
the total should be 24.15 while my function gives out 28.0336190345.
Can someone please help and see where in my math I am doing something wrong. Thank You in advance.