In this program, we will take a string as input and replace different characters in string at once.
Steps to solve the program
- Take a string as input and create an empty string.
- Add each character from the given string to the empty string after replacing different characters.
- Use for loop for this purpose.
- Print the output.
#Input string
string = "Sqatool python"
new_str = ""
for char in string:
if char == "a":
new_str += "1"
elif char == "t":
new_str += "2"
elif char == "o":
new_str += "3"
else:
new_str += char
#Printing output
print(new_str)
Output :
Sq1233l py2h3n