Write a program which asks user to enter value for number of line and then according to input following pattern should be displayed. - Pratik Ghelani

Pratik Ghelani

Breaking

Sunday, May 10, 2020

Write a program which asks user to enter value for number of line and then according to input following pattern should be displayed.

Input:-


num = int(input("Enter the number of pattern:"))
def pattern(n):
    for i in range(1, n + 1):
        for j in range(1, 2 * n + 1):
            if (i < j):
                print("", end = " ");
            else:
                print("*", end = "");
            if (i <= ((2 * n) - j)):
                print("", end = " ");
            else:
                print("*", end = "");
        print("");
    for i in range(1, n + 1):
        for j in range(1, 2 * n + 1):
            if (i > (n - j + 1)):
                print("", end = " ");
            else:
                print("*", end = "");
            if ((i + n) > j):
                print("", end = " ");
            else:
                print("*", end = "");
        print(""); 
pattern(num);



Output:-


No comments:

Post a Comment