-5

How to make program like this.???

Input : 4

    *
   * *
  *   *
 * * * *

I would love to know how to do this, it's been bugging me all week but it was only an extra credit question so my teacher never explained how to do it!! :( https://i.stack.imgur.com/qlyGu.jpg

1 Answers1

0

I thought this would be fun to try, here is my solution:

PROMPT_MSG = "Please enter a whole number, greater than 1"
PROMPT_MSG_ERR = "Oops! Please try again.."

def validate_input(input):
    try:
        assert int(input) > 1
        return int(input)

    except (ValueError, AssertionError) as e:
        print PROMPT_MSG_ERR + "\n"
        main()

def main():
    user_input = raw_input("{0}: ".format(PROMPT_MSG))
    valid_input = validate_input(user_input)

    if valid_input:
        print "{0}*".format(" " * valid_input)
        for i in range(0, valid_input)[1:-1]:     
            print "{0}*{1}*".format(
                (" " * (valid_input - i)),
                (" " * (i + (i-1))),
            )
        print " *" * valid_input

if __name__ == '__main__':
    main()
Sjshovan
  • 310
  • 2
  • 5