.Write a program to input a string and replace first and last letter of each word with asterisk(‘*’) sign.
Answers
Answered by
6
The following codes 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
Math,
2 months ago
India Languages,
2 months ago
Math,
2 months ago
Social Sciences,
4 months ago
English,
1 year ago
Hindi,
1 year ago