Why am I getting AttributeError?

Hi, I am learning about stacks and I got a problem. When I type python3 -c 'import script; script.get_input()' I am getting AttributeError: module ‘script’ has no attribute ‘get_input’
What did I wrong?

from stack import Stack

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

#Create the Stacks
left_stack = Stack("Left")
middle_stack = Stack("Middle")
right_stack = Stack("Right")
stacks = [left_stack, middle_stack, right_stack]

#Set up the Game
num_disks = int(input("\n How many disks do you want to play with?"))
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 {0} moves".format(num_optimal_moves))
#Get User Input
def get_input():
  choices = [stack.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("")

I copied and pasted your code into the CA editor, clicked “Save”, then (again direct copy-paste) python3 -c 'import script; script.get_input()' … and it ran fine!

So I can’t explain the error.

To run your script, all you really need at the $ prompt is:

python3 script.py

… if you’re trying to test the get_input() function, just run it from within the script with get_input() at the bottom, flush with the left margin.


Once you get it going, check out my ASCII “Graphic” add-on, as well as the self-solving recursive version.