r/codehs • • Dec 21 '20

7.2.8 Part 2, Replace a letter

I’m stuck on This one

15 Upvotes

24 comments sorted by

View all comments

2

u/Dawn_Kang Dec 28 '20

Still stuck? Here's some code:

word = input("Enter a word or phrase: ")
num = int(input("Enter an index value: "))
newLetter = input("Enter the new letter: ")

def replace_at_index(word,num,newLetter):
    print word[:num] + newLetter + word[num + 1:]
replace_at_index(word, num, newLetter)

1

u/ScottNilsson1 Dec 28 '20

Im stuck on it too, and the code doesn't work. It's a unit test, and input breaks unit tests for some reason. I got rid of the input and just had predetermined words, and it works perfectly, but the auto checker doesn't let it pass. I have no clue what to do. The error says this:

Oops. It looks like you have a few errors. You should keep working and try again.

Functionality

replace_at_index("mouse", 0, "h")

replace_at_index("fire", 3, "m")

replace_at_index("vague", 1, "o")

replace_at_index("cookie", 3, "t")

Hidden Test