Question

PYTHON 1.      Complete the attached template program pattenrs.py to create and display a number of patterns. The...

PYTHON

1.      Complete the attached template program pattenrs.py to create and display a number of patterns. The program works with a single digit. The default value is 6, but user to change it as a menu selection.

2.      Program should display the patterns below. Additionally, you need to create your own pattern.

3.      Do not modify myPatterns6 driver.

4.      Make sure you document the program and its functions.

5.      PatternI is already implemented.

6.      Create five additional functions (similar to PatternI function) to implement Patterns II, III, IV, V, and VI (your own).

7.      Use nested loops to print the other patterns and the pattern of your own choice.

Pattern I          Pattern II         Pattern III                   Pattern IV       Pattern V      Your Own

1                      123456                           6                  123456            12345654321

12                    12345                           56                   23456              234565432

123                  1234                           456                      3456                3456543

1234                123                          3456                       456                  45654

12345              12                           23456                         56                    565

123456            1                           123456                            6                      6

Homework Answers

Answer #1

def p1(n):

    for i in range(0,n):

        for j in range(1,i+2):

            print(j,end="")

        print()

        

def p2(n):

    for i in range(n-1,-1,-1):

        for j in range(1,i+2):

            print(j,end="")

        print()

        

def p3(n):

    for i in range(n-1,-1,-1):

        for j in range(1,i+1):

            print(" ",end="")

        for j in range(i+1,n+1):

            print(j,end="")    

        print()

        

def p4(n):

    for i in range(0,n):

        for j in range(1,i+1):

            print(" ",end="")

        for j in range(i+1,n+1):

            print(j,end="")      

        print()

        

def p5(n):

    for i in range(0,n):

        for j in range(1,i+1):

            print(" ",end="")

        for j in range(i+1,n+1):

            print(j,end="")

        for j in range(n-1,i,-1):

            print(j,end="")

        print()

        

n=int(input("Enter a number: "))

p1(n)

print("\n\n")

p2(n)

print("\n\n")

p3(n)

print("\n\n")

p4(n)

print("\n\n")

p5(n)

print("\n\n")

#SAMPLE OUTPUT

PLEASE LIKE IT RAISE YOUR THUMBS UP
IF YOU ARE HAVING ANY DOUBT FEEL FREE TO ASK IN COMMENT SECTION

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT