CodeSolved

Solved Programming Questions & Exercises

Pyramid display

Practice Easy 894/ Download 746 Views

Write a program that receives a word from the user and prints it as follows:

Input: Amir

a
AM
ami
Amir
ami
AM
a

10 Answers

txt = input("Enter your text : ") # Get the text

for i in range(len(txt)): # Pyramid printing
    print(txt[:i])
for j in range(len(txt)):
    print(txt[:len(txt)-j])
print("") # To create a distance

It was very good Alireza.safaei


def a_pyramid(txt): # Define function
    for i in range(len(txt)): # Pyramid printing
        print(txt[:i])
    for j in range(len(txt)):
        print(txt[:len(txt)-j])
    return "" # And create NON distance because of not being displayed

text = input("Enter your text: ") # Get the text
print(a_pyramid(text)) # Calling the function
word =input("namr: ")
for i, l in enumerate(word):
    print(word[:i+1])
Farbod.313 Download Python
name = input("Enter name : ")
len_name = len(name)
for x in range(1, len_name + 1):
    print(name[:x])
for y in range((len_name) - 1 , 0 , -1) :
    print(name[:y])
Emrimo Download Python
word = (input("Please enter your word: "))
temp = ""
res = []
word_lst = list(word)
for i in range(len(word_lst)):
    temp += word_lst[i]
    res.append(temp)
    print(res[i])
for i in range(1,len(word_lst)):
    print(res[-i-1])
Behcoder Download Python
word = (input("Please enter your word: "))
for i in range(len(word)+1):
    print(word[:i])
for i in range(len(word)):
    print(word[:-i-1])
Behcoder Download Python
a=input('word:')
print(a[:1])
print(a[:2])
print(a[:3])
print(a[:4])
print(a[:5])
print(a[:6])
Maryam.n Download Python
inp = input("Enter name: ")

for i in range(2*len(inp)-1):
    if i<len(inp):
        print(inp[0:i+1])
    else:
        print(inp[0:len(inp)-i-1])
Najme.s.y Download Python
def print_pattern(word):
    """الگوی مورد نظر را برای کلمه ورودی چاپ می‌کند."""
    # Part One Printing: From one character to all characters
    for i in range(1, len(word) + 1):
        print(word[:i])
    
    # Printing Part Two: From n-1 character to a character
    for i in range(len(word) - 1, 0, -1):
        print(word[:i])

def main():
    # Receive a word from the user
    word = input("لطفاً یک کلمه وارد کنید: ")
    
    # Pattern printing
    print_pattern(word)

# Implementation of the main function
if __name__ == "__main__":
    main()
Mma123 Download Python
in_put=input(f"Enter the letter:")
letter_list=[str(i) for i in in_put]
for h in range(1,2):
    for i in range(1,len(letter_list)+1):
        print(letter_list[:i])

    for i in range(1,len(letter_list)):
        print(letter_list[:-i])

Submit answer

Submitting answers is currently unavailable.

×
×
Close