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.
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)
Comments
Leave a comment