Character Parallelogram program in Python


Character Parallelogram program written in Python was developed to show the Working of for loop in Python along with string slicing. The program was written using Python 3.6 and Visual Code editor for Windows.

Character Parallelogram Python Program takes a string from Input and print the characters available in this string in the format of a parallelogram. Here is the python code for character Parallelogram.

# Program to print character paralleogram
# made by           : rakesh kumar
# Licence           : MIT
def printString(string):
    n = len(string)
    for i in range(0,n):
        print(string[i],end=" ")

string  = "TESTINGPROGRAM"
n = len(string)
# print(n)
for i in range(1,n+1):
    for j in range(i,n):
        print("  ",end="")
    printString(string[0:i])
    print()
for i in range(1,n+1):
    printString(string[i:])
    print()

Check the same

The above program takes a string from a user using standard Python function INPUT() that actually receives everything as a string so there is no need to convert this into a string.
4tht Line finds out the total no of chars in this string, Next line is responsible for running a loop through 1 to n as the range command always runs one step less defined in range() function this +1 is added here.

5th Line run again a for loop that is responsible to print spaces before printing the actual sliced string. Here we have added end=” ” so that the print() function does not add a new line automatically.

6th line takes your string ans slice it from the beginning to the point of loop. 7th line print is here only to generate a new blank line.

7th, 8th, and 9th line are, I think, self-explanatory.

The output of Character Parallelogram is

character parallelogram in python

Though, We have taken care to prepare this Character parallelogram program as per the Python coding standard. Still, if you find any better way to code this program, do not hesitate to contact us. We will print your code with full credentials.

 

Print Friendly, PDF & Email

Related Posts

If you like CBSEToaday and would like to contribute, you can also write an article using submit article or mail your article to contribute@cbsetoday.com See your article appearing on the cbsetoday.com main page and help other students/teachers.