Functions · 11 / 27 Exercise Medium

Replace character in a string

Objective

Create a Python program that defines a function called change_letter() to modify a character of a text. The function receives as parameters the text, a position (0-based) and a letter. The program must validate that the position is inside the text and then display the resulting text on the screen.

Instructions

  • The program asks the user for a text.
  • Then it asks for a position (0-based) inside the text and validates it. If it is not valid, it shows an error message and ends.
  • Next, the user enters a letter.
  • The change_letter() function replaces the character at that position.
  • The program displays the new text on the screen.
Input
exampl3
6
e
Output
New text: example

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise