In this program, we will take a string as input and replace the second occurrence of any char with the special character $.
Steps to solve the program
- Take a string as input and create an empty string.
- Using For loop add each character of the given string to the empty string.
- If a character repeats then do not add that character add $ instead.
- Print the output.
#Input string
str1 = "Programming"
result = ''
#checking for repeated char
for char in str1:
if char in result:
result = result + "$"
else:
result = result + char
#Printing output
print("Result :", result)
Output :
Result : Prog$am$in$