Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 'builtin_function_or_method' object is not subscriptable error' mean? [closed]

Tags:

python-3.x

So I'm trying to program a good ol' game of war and I'm getting an error when I try to move an object (a card) from one list (hand) to another. There have been some other posts about this but I wasn't able to piece together what to do... Here's the code:

import random
cardvalues = {"ace" : 13 , "2" : 2 , "3" : 3 , "4" : 4 , "5" : 5 , "6" : 6, "7" : 7 , "8" : 8 , "9" : 9, "10" : 10 , "jack" : 11 , "queen" : 12 , "king" : 13}
suits = {"clubs" : 1, "diamonds" : 2 , "spades" : 3 , "hearts" : 4}
deck = []
currentDeck = []

class card:
    def __init__ (self, value, suit):
        if value not in cardvalues:
            raise RuntimeError("must input valid card value")...

### [code here was erased because it's not causing the problem]

def battle():            
    if hand1[0] >= hand2[0]:
        hand1.append[hand2.pop(0)] #The error happens in this function in the .append
        print("player 1 won the battle")
    elif hand1[0] < hand2[0]:
        hand2.append[hand1.pop(0)]
        print("player 2 won the battle")
    else:
        raise RuntimeError("something wrong")


while len(hand1) > 0:
    while len(hand2) > 0:
        battle()
if len(hand1) == 0:
    print("PLAYER 2 WON THE WAR")
elif len(hand2) == 0:
    print("PLAYER 1 WON THE WAR")
else:
    print("no one won?")

Thanks!

Not only do I need help finding my error, but what does it mean?

like image 870
Paco Poler Avatar asked Nov 11 '15 18:11

Paco Poler


1 Answers

You used [] instead of () when trying to call append.

like image 101
Scott Hunter Avatar answered Oct 23 '22 12:10

Scott Hunter