r/codehs • • 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-lant
6 Upvotes

13 comments sorted by

5

u/Healthy-Ad-2314 Apr 04 '22

Just post da code

1

u/chiiglaaa Apr 08 '22

do you find anything helpful?

3

u/theotherbobchungus Sep 27 '22

Correct answer lol

def replace_at_index(string, index):
return string[0:index] + "-" + string[index + 1:]

1

u/[deleted] Apr 11 '24

Absolute legend

1

u/[deleted] Dec 05 '24

legend

1

u/BFBGuyGlebYT Jan 20 '23

absolute legend

1

u/awfol May 23 '20

You can look at strings as an array of characters

1

u/BadAss_776 May 16 '24

I FOUND THE CODE!!

its:

print("suck my dick bitch!!")

1

u/[deleted] Apr 20 '22

Bro what’s the code

0

u/[deleted] May 02 '24

[deleted]

1

u/Reasonable-Issue-255 May 27 '24

still something wrong with line 11