Computer Science, asked by kanpurhardwareandtoo, 4 months ago

.Write a program to input a string and replace first and last letter of each word with asterisk(‘*’) sign.​

Answers

Answered by Equestriadash
6

The following c‎odes have been written using Python.

#obtaining the input

s = input("Enter a string: ")

#creating an empty string

new_str = ""

#using a loop to traverse through the string

for i in s.split():

   #assigning the new string to a new variable

   ns = "*" + i[1:-1] + "*"

   #appending the new variable to the declared empty string

   new_str = new_str + ns + " "

#printing the final output

print("The new string is: ", new_str.rstrip())

A for loop is an iteration statement used to traverse through something. In this case, we're traversing through the word(s) of the string by using s.split() that splits the string wherever there is a space character.

Similar questions