Answer to Question #307112 in Python for ratul

Question #307112

Write a python program that takes 2 inputs from the user. The first input is a string and the second input is a letter. The program should remove all occurences of the letter from the given string and print the output. If the letter is not found in the string and the length of string is greater than 3, then remove the first letter and last letter of the given string and print it. Otherwise print the string as it is. You can assume that all the input will be in lowercase letter.


1
Expert's answer
2022-03-10T18:08:15-0500
src = input()
ch = input()

res = ''
has_char = False
for c in src:
    if c == ch:
        has_char = True
    else:
        res += c


if not has_char and len(res) > 3:
    res = res[1:-1]


print(res)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS