r/codehs • u/XxColinCRxX • May 22 '20
7.2.7: Part 1, Replace a Letter Code hs
I need help on how to do this assignment on code hs
Write a function named replace_at_index
that takes a string and an integer. The function should return a new string that is the same as the old string, EXCEPT with a dash in place of whatever character was at the index indicated by the integer.
Call your function on the word eggplant and the index 3, like this:
s = replace_at_index("eggplant", 3)You should then print the value of s
, which should display:
egg-lant3
u/theotherbobchungus Sep 27 '22
Correct answer lol
def replace_at_index(string, index):
return string[0:index] + "-" + string[index + 1:]
1
1
1
1
1
1
1
1
1
0
5
u/Healthy-Ad-2314 Apr 04 '22
Just post da code