Recently i starded learning python, this would be my first "useful" script (simple word learning script). I got a "TypeError: 'dict' object is not callable", but it's unrelevant in this case(alteast for me).
def discounted_price(total,discount,minprice=100):
fruits = ['Apple','Avocado','Banana','Blackberries','Blueberries','Cherries','Date Fruit','Grapes','Guava','Jackfruit','Kiwifruit']
prices = [6,5,3,10,12,7,14,15,8,7,9]
d1 = dict(zip(fruits,prices))
chart = ['Blueberries','Blueberries','Grapes','Apple','Apple','Apple','Blueberries','Guava','Jackfruit','Blueberries','Jackfruit']
fruit_price = None
counter_item = {}
for i in chart:
if i in counter_item:
counter_item[i] +=1
else:
counter_item[i] =1
counter_item
fruit_price = {}
for i, j in d1.items():
for x, y in counter_item.items():
if i == x:
fruit_price[i]=(j*y)
fruit_price
total_price = 0
for i in fruit_price.values():
total_price += i
total_price
minprice=100
discount=0
if total_price<minprice:
discount=total_price
else:
discount=total_price*(10/100)
discounted_price=total_price-discount
return discounted_price
print(discounted_price(total_price(counter_item(chart),fruit_price),10,minprice=100))
Type error
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-38-7dbc173506d2> in <module>
30 discounted_price=total_price-discount
31 return discounted_price
---> 32 print(discounted_price(total_price(counter_item(chart),fruit_price),10,minprice=100))
TypeError: 'dict' object is not callable
Thanks!