Towers of hanoi project help

Hi I am stuck on the Tower of Hanoi project.

Whenever I try to run the script using python3 -c ‘import script; script.get_input()’ in bash I get this error → AttributeError: module ‘script’ has no attribute ‘get_input’

But, i’ve clearly defined the get_input function in the program. Any help would be appreciated!


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 += [left_stack, middle_stack, 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 disk in range(num_disks, 0, -1):


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("")

Is there a reason you’re running with the -c flag?

Be careful with python in this lesson since you’re using python3 syntax some of the cc environments (like this one) have both options available so scripts should be run with python3.

Perhaps check the attributes of that module to make sure things are working as you expect. If you adapted the string you pass to print(dir(script)) after import you could check exactly what names it does have.

In the future if you’re posting code to the forums please see- How do I format code in my posts? or consider gists, pastebins or similar for longer code.

The -c flag is fine. The course asks you to copy and paste that command into the Terminal to try out the function.

Agreed - it’d be helpful to see the code properly formatted. I wonder if perhaps the function hasn’t been properly indented or something similar.