Ejemplo n.º 1
0
def main():
    '''function main
       parameter: none
       returns: nothing
       does: asks user to enter number of disks and checks conditionals
             of if they enter anything other than 1-8 to print again.
             Once they enter a correct value we use initialize tower
             function to return towers dictionary so we can utilize the
             global variable TOWERS
             move towers uses the value of towers dictionary to create and
             print towers then breaks
    '''
    while True:
        #try except to accept when user doesn't enter integer and reprompts them
        try:
            user_input = int(input("Enter a number between 1-8 for disks? "))
            if user_input < 1:
                print("Ay Caramba!can't move disk from empty tower")
                continue
            elif user_input > 8:
                print("Ay Caramba!Please enter a number between 1-8")
                continue
        except ValueError:
            print("Ay Caramba!, please try again")
            continue
        else:
            initialize = hanoi_viz.initialize_towers(user_input, TOWERS[0],
                                                     TOWERS[1], TOWERS[2])
            movement = move_tower(user_input, TOWERS[0], TOWERS[1], TOWERS[2],
                                  initialize)
            break
Ejemplo n.º 2
0
def main():

    # creates a list of allowed number of disks a user may request
    allowed_disks = [1, 2, 3, 4, 5, 6, 7, 8]
    num_disks = 0  # sets number of disks to 0
    while num_disks not in allowed_disks:  # creates loop to start user prompt as long as user prompt not in allowed_disks
        try:  # sets a try function to help catch value errors
            print('Please choose a number between 1 and 8!'
                  )  # tells user how many they may choose
            num_disks = int(
                input(
                    'How many disks are on the starting tower? (Only allowed 1 to 8 disks!) '
                ))  # requests user's number
        except ValueError:  # creates a Value Error exception if user puts in anything but a number
            print('Please pick a number between 1 to 8, dummy!'
                  )  # reminds them the options
            num_disks = int(
                input(
                    'How many disks are on the starting tower? (Only allowed 1 to 8 disks!) '
                ))
    towers = initialize_towers(
        num_disks, a, b, c
    )  # initiliazes the towers function to create towers dictionary, saves it to towers constant
    move_tower(
        a, b, c, towers, num_disks
    )  # calls upon the created move towers function to intiliaze overall program
Ejemplo n.º 3
0
def main():

    # prompts the user to enter an integer 1-8 and reprompts them if they don't
    try:
        num_disks = 0
        while num_disks < 1 or num_disks > 8:
            num_disks = int(input("What is the number of disks (1-8)? \n"))

    except ValueError:
        num_disks = int(input("Please enter an integer (1-8)?"))

    # creates tower dictionary
    towers = hanoi_viz.initialize_towers(num_disks, 'A', 'B', 'C')

    # determines and visualizes steps for disks
    move_tower(num_disks, towers, 'A', 'B', 'C')
Ejemplo n.º 4
0
def main():

    # Prompt the user for the number of disks until valid input is given
    num_disks = 0
    while num_disks > MAX or num_disks < MIN:
        try:
            num_disks = int(input("Please enter an integer from 1 - 8:\n"))

        # Tell the CPU how to handle a ValueError when something other than
        # an integer is entered by the user
        except ValueError:
            print("Input is required to be an integer, please try again.")

    # Create the dictionary of towers using module's function
    towers = hanoi_viz.initialize_towers(num_disks, NAME[0], NAME[1], NAME[2])

    # Use a recursive function to move all rings from one tower to another
    move_tower(num_disks, NAME[0], NAME[1], NAME[2], towers)
def main():
    count = 0
    num_disks = prompt_num_disks()
    towers = initialize_towers(num_disks, 'A', 'B', 'C')
    move_tower(num_disks, 'A', 'B', 'C', towers)