0

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!

3
  • stackoverflow.com/questions/6634708/… Does this help? Commented Jun 6, 2020 at 4:04
  • You are re-using function names as variable names. Commented Jun 6, 2020 at 4:24
  • I have tried changing the sign '( )' to '[ ]' but still error sir Commented Jun 6, 2020 at 4:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.