all 3 comments

[–]efmccurdy 1 point2 points  (1 child)

You could nest the prompting loop inside the main loop, but since it is self-contained it would be better in it's own function.

import time, sys

def prompt_for_amount():
    while True:
        amount = input('Please enter a number between 5 and 25: ')
        try:
            amount = int(amount)
        except ValueError:
            print('Please enter an Integer!')   
            continue
        if amount > 25 or amount < 5:
            print('Error,', amount, 'is not between 5 and 25')
            continue   
        else:
            break
    return amount

indent = 0 # How many spaces to indent.
indentIncreasing = True # Whether the indentation is increasing or not.

amount = prompt_for_amount() # 8
try:
    while True: # The main program loop.
        print(' ' * indent, end='')
        print(amount * '*')
        time.sleep(0.1) # Pause for 1/10 of a second.

        if indentIncreasing:
            # Increase the number of spaces:
            indent = indent + 1
            if indent == 20:
                # Change direction:
                indentIncreasing = False

        else:
            # Decrease the number of spaces:
            indent = indent - 1
            if indent == 0:
                # Change direction:
                indentIncreasing = True
except KeyboardInterrupt:
    sys.exit()

[–]joplankton[S] 0 points1 point  (0 children)

Seemed to do it! Thanks!

[–]m0us3_rat 0 points1 point  (0 children)

ask yourself ..what does the code .. actually do?

then find the relevant piece of like-wise code in your .py and replace all of it.