Replace Character
Python
Easy
3 views
Problem Description
A string s is provided, and two characters a and b. Replace every a with b and output result.
Input Format
Line1: s. Line2: a b.
Output Format
One line result.
Official Solution
import sys
lines=sys.stdin.read().splitlines()
if not lines: sys.exit(0)
s=lines[0]
parts=(lines[1] if len(lines)>1 else '').split()
if len(parts)<2:
sys.stdout.write(s)
else:
a=parts[0][0]
b=parts[1][0]
sys.stdout.write(s.replace(a,b))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!