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
Solution
To print the given string in a pattern, we can follow these steps:
- Read the input string.
- Initialize an empty string variable to store the pattern.
- Iterate through each character in the input string, starting from the last character.
- Append the current character to the pattern string.
- 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!
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
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.