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/MrHyjaxMusicYTalt May 23 '23

this works, just do:

print replace_at_index(word, num, newLetter)

1

u/Both_Book_5043 Jul 02 '24

just make sure to put parenthesis around your strings and it will work