Ask coding questions

← Back to all posts
what is this error ? what am i doing wrong ?
Iamvik98

Traceback (most recent call last):
File "main.py", line 83, in <module>
user_score = calculate_score(user_cards)
File "main.py", line 46, in calculate_score
return sum(cards)
TypeError: unsupported operand type(s) for +: 'int' and 'function'

The above error is shown when i'm running this code. Help me through this.

Answered by ch1ck3n [earned 5 cycles]
View Answer
Voters
maxina
Iamvik98
Comments
hotnewtop
ch1ck3n

Ah i've found the answer:
replace line 83 with this:

user_score = calculate_score(user_cards())

thank you @QuickV for pointing me in the right direction

QuickV

yay I helped...

At least I think I did...

@ch1ck3n

Iamvik98

user_cards is not a function but a list. I don't think this would do. Problem's root is at line 46, can u help me with what's going on there ? @ch1ck3n

ch1ck3n

@Iamvik98 i think in cards there is an int and a function in it

ch1ck3n

@Iamvik98

you're trying to add two functions together

ch1ck3n

@Iamvik98 alright i finally found the answer
https://replit.com/@ch1ck3n/blackjack-start-1#main.py

i have changed line 79 and 80 to

Iamvik98

Thanks man ! It's working. You're a champ [email protected]

QuickV

"In order to call a function you must add parenthesis after the function name, as well as any required parameters"... That could be the answer to your problem.

Iamvik98

All that is done, if u can find where it's missing u can let me know. @QuickV

QuickV

k :) @Iamvik98

QuickV

The console pretty much gives you an explanation of what's going on .-.

ch1ck3n

@QuickV he doesn't understand the error so you're supposed to answer his question

don't comment if it doesn't contribute to the question or conversation

QuickV

k... I tried to answer his question in a new comment :) @ch1ck3n

Iamvik98

i'm passing in a list(an iterable) in the sum function but still getting this error. My brain cells aren't working at this point, couldn't think of what's going wrong.
@ch1ck3n

QuickV

I think @ch1ck3n just answered your question 🤔 @Iamvik98