29.7k views
1 vote
Given string userText on one line and character fourthChar on a second line, change the fourth character of userText to fourthChar.

Ex: If the input is:

cheetah
v

then the output is:

chevtah

Note: Assume the length of string userText is greater than or equal to 4.

Given string userText on one line and character fourthChar on a second line, change-example-1
User Neijwiert
by
4.2k points

1 Answer

5 votes

Answer:

# Get the input from the user

userText = input()

fourthChar = input()

# Replace the fourth character of the string with the new character

userText = userText[:3] + fourthChar + userText[4:]

# Print the modified string

print(userText)

Step-by-step explanation:

This code first gets the input from the user and stores it in the userText and fourthChar variables. It then uses string slicing to replace the fourth character of the string with the new character. Finally, it prints the modified string.

The input string is cheetah, and the fourth character is e. The code replaces this character with the new character v, resulting in the modified string chevtah.

User Bruce Zhang
by
4.7k points