강의

멘토링

커뮤니티

Inflearn Community Q&A

ho67216346's profile image
ho67216346

asked

Getting Started with Programming: Challenge! 45 Python Basic Grammar Exercises (Inflearn Original)

Calculate Dict Sum (Dict Items Sum)

딕셔너리 인트문제

Written on

·

36

0

# 11.Dict Items Sum

d = {'a': 17,'b': 114,'c': 247, 'd': 362, 'e': 220, 'f': 728, 'g': -283, 'h': 922}

# 방법1

total = 0

for i in d.values():

total += i

print(f'ex1 결과 : {total}')

# 방법2

print(f'ex2 결과 : {sum(d.values())}')

# 방법3

print(f'ex3 결과 : {sum([d[item] for item in d])}') # 괄호 제외

TypeError                                 Traceback (most recent call last)
Cell In[13], line 15
     11 print(f'ex1 결과 : {total}')
     14 # 방법2
---> 15 print(f'ex2 결과 : {sum(d.values())}')
     18 # 방법3
     19 print(f'ex3 결과 : {sum([d[item] for item in d])}')

TypeError: 'int' object is not callable

인트가 호출이 안 된다고 뜨는데 이유가 뭔지 알 수 있을까요?

 

python

Answer

This question is waiting for answers
Be the first to answer!
ho67216346's profile image
ho67216346

asked

Ask a question