Answer to Question #304544 in Python for reyadh

Question #304544

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


1
Expert's answer
2022-03-01T14:00:19-0500
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)

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