Question: My Code: def create _ fancy _ username ( username: str ) - > str: replacements = { ' a ' : ' @ '
My Code: def createfancyusernameusername: str str:
replacements a: @e: i: o: s: $g: gb:
counts char: for char in replacements
fancyusername
for char in username:
if char in replacements:
countschar
if countschar;
fancyusername.appendreplacements char
else:
fancyusername.appendchar
else:
fancyusername.appendchar
return joinfancyusername Examples:
createfancyusernameusername: usrnam
createfancyusernameassociation: a$sci@tiOn
createfancyusernamemississippi: mi$ss$ipp
def createfancyusernameusername: str str:
replacements a: @e: i: o: s: $g: b:
counts char: for char in replacements
fancyusername
for char in username:
if char in replacements:
countschar
if countschar:
fancyusername.appendreplacementschar
else:
fancyusername.appendchar
else:
fancyusername.appendchar
return joinfancyusername
What I am supposed to get:
createfancyusernameusername: usrnam
createfancyusernameassociation: a$sci@tin
createfancyusernamemississippi: mi$ss$ipp
What I got:
usernam
as$oci@tn
mis$s$ipp
Help me fix my code
Description: Write a function that takes a username as input and replaces certain characters with digits or special characters that resemble them visually. However, replacements should only be made on the even occurrence of those characters in the username, not the odd occurrences. In other words, the first time you see a character that can be replaced, we won't change it The second time you see a character that can be replaced, you should, and so on Note that the input will always be lowercased.
Arguments:
username type: str: The input username.
Returns:
fancyusername type: str: The modified username with replacements made.
Character Mappings:
@
number zero
$
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
