Knowee
Questions
Features
Study Tools

Print follwing string like pattern.Input format :StringOutput format :PatternSample inputhelloSample outputo ol oll olle olleh

Question

Print following string like pattern.

Input format:
String

Output format:
Pattern

Sample input
hello

Sample output

  o
 ol
oll
olle
olleh
🧐 Not the exact question you are looking for?Go ask a question

Solution

To print the given string in a pattern, we can follow these steps:

  1. Read the input string.
  2. Initialize an empty string variable to store the pattern.
  3. Iterate through each character in the input string, starting from the last character.
  4. Append the current character to the pattern string.
  5. Print the pattern string.

Here is the code in Python:

# Step 1: Read the input string
input_string = input("Enter a string: ")

# Step 2: Initialize an empty string variable
pattern = ""

# Step 3: Iterate through each character in the input string
for i in range(len(input_string)-1, -1, -1):
    # Step 4: Append the current character to the pattern string
    pattern += input_string[i]
    
    # Step 5: Print the pattern string
    print(pattern)

For the given input "hello", the output will be:

o
ol
oll
olle
olleh

I hope this helps!

This problem has been solved

Similar Questions

Print follwing string like pattern.Input format :StringOutput format :PatternSAMPLE INPUT helloSAMPLE OUTPUT oolollolleolleh

Write your own printf function:Create a manPrint a simple characterPrint a stringHandle %dHandle %x

Given a string as input . Print the frequncy of each character in the string in alphabetical order of characters

Write a python code to get the given pattern without using ‘FOR’ loop. A minimum of six WHILE LOOPS must be used effectively to get the output.

Write a python program that traverses through an input string and prints its characters indifferent lines – two characters per line

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.