Another error

Report a typo

The function that you can see below is supposed to add underscores to the given string, such that each character would be surrounded by them. For example, add_underscores("error") should return "_e_r_r_o_r_".

However, it contains bugs. If we run it now, we won't get the expected output:

print(add_underscores('hello'))
# o_

Use the IDLE's debugger to find the error and correct it in the code.

If you already see what the problem with the code is, don't just correct it. The point of this topic is to learn how to use IDLE's debugger, so use this opportunity to practice.

Sample Input 1:

error

Sample Output 1:

_e_r_r_o_r_
Write a program in Python 3
def add_underscores(word):
new_word = '_'
for i in range(len(word)):
new_word = word[i] + '_'
return new_word

word = input()
print(add_underscores(word))
___

Create a free account to access the full topic