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.
=====================================================================
Sample Input 1:
tanjiro kamado a
Sample output 1:
tnjiro kmdo
line = input()
string = line[:-2]
ch = line[-1]
res = ''
for c in string:
if c != ch:
res += c
if len(res) == len(string):
if len(res) > 3:
res = res[1:-1]
print(res)
Comments
Leave a comment