Getting error when running script to get input not sure what the error message means

from stack import Stack

print("\nLet's play Towers of Hanoi!!")

#Create the Stacks

stacks = ['']

left_stack = Stack('Left')

middle_stack = Stack('Middle')

right_stack = Stack('Right')

stacks.append(left_stack)

stacks.append(middle_stack)

stacks.append(right_stack)

#Set up the Game

num_disks = int(input("\nHow many disks do you want to play with?\n"))

while num_disks < 3:

  num_disks = int(input("Enter a number greater than or equal to 3\n"))

for i in range(num_disks, 0 , -1):

  left_stack.push(i)

num_optimal_moves = (2**num_disks)-1

print("\nThe fastest you can solve this game is in " + str({num_optimal_moves}) + " moves")

#Get User Input

def get_input():

  choices = [stacks.get_name()[0] for stack in stacks]

  while True:

    for i in range(len(stacks)):

      name = stacks[i].get_name()

      letter = choices[i]

      print("Enter {0} for {1}".format(letter,name))

    user_input = input("")

Now the error I get is "$ python3 -c ‘import script; script.get_input()’

Let’s play Towers of Hanoi!!

How many disks do you want to play with?
5

The fastest you can solve this game is in {31} moves
Traceback (most recent call last):
File “”, line 1, in
File “/home/ccuser/workspace/stacks-proj/script.py”, line 27, in get_input
choices = [stacks.get_name()[0] for stack in stacks]
File “/home/ccuser/workspace/stacks-proj/script.py”, line 27, in
choices = [stacks.get_name()[0] for stack in stacks]
AttributeError: ‘list’ object has no attribute ‘get_name’
$ "

I have a stack.py with a get_name function properly defined as well.

I’d check your names, though the Stack() might have a get_name() method, it looks like stacks refers to a list:

1 Like

Yeah I added an “s” … Thank you!!!