Knowee
Questions
Features
Study Tools

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

Question

Print the following string like pattern.

Input format:
String

Output format:
Pattern

SAMPLE INPUT
hello

SAMPLE OUTPUT
oolollolleolleh

🧐 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. For each character, append it to the pattern string.
  5. Append the substring from the first character to the current character to the pattern string.
  6. Repeat steps 4 and 5 until all characters have been processed.
  7. Print the pattern string as the output.

Here is the code implementation 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 character to the pattern string
    pattern += input_string[i]
    
    # Step 5: Append the substring to the pattern string
    pattern += input_string[:i]

# Step 7: Print the pattern string
print("Pattern:", pattern)

For the given input "hello", the output will be "oolollolleolleh".

This problem has been solved

Similar Questions

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

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.

Without using any string methods, try to print the following:Note that "" represents the consecutive values in between.

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.