Quantcast
Channel: User Federico klez Culloca - Stack Overflow
Viewing all articles
Browse latest Browse all 508

Answer by Federico klez Culloca for TypeError: 'int' object is not subscriptable in trying to make a blackjack game

$
0
0

The problem is that when evaluating player_cards[0][1][2][3][4] python would first evaluate player_cards[0] which is a number (let's suppose it's 4) and then try to do something like 4[1][2][3][4], so it tries to interpret 4[1] which obviously fails because 4 cannot be subscripted, hence the error.

If you want the first at most 5 elements of the array you can use a slice, so

{player_cards[0:4]}

Which, since we're starting from the beginning of the array, can be abbreviated to

{player_cards[:4]}

Viewing all articles
Browse latest Browse all 508

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>