Respuesta :
Answer:
Python 3 code:
n = int(input())
rev_str = [ ]
for i in range(n):
s = str(input())
s.split()
words = s.split(' ')
string = [ ]
for word in words:
string.insert(0, word)
rev_str.append(" ".join(string))
#print(" ".join(string))
for i in range(len(rev_str)):
print(rev_str[i])
Explanation:
Following are the Python program to reverse the string:
Program Explanation:
- In the given code "n" variable is defined that use the input with int method to input value.
- In the next step, an empty list is defined, and after this two for loop is declared that reverse the inputs sting.
- After reverseing the value another for loop is defined that prints reverse value.
Program:
n=int(input("Enter number of Strings : ")) #defining n variable to input value array=[]#defining an empty list print("Enter strings:")#print message for i in range(n):#defining a loop that input string value array.append(input()) #adding value in array reverse=[] #defining an empty list for i in range(len(array)): #defining loop for reverse word s=array[i] #holding list value in s variable new="" #defining a string variable new1="" #defining a string variable for j in range(len(s)): #defining loop for reverse string value if(s[j]==" "): #using if block thta check whether the character is space or not new=s[j]+new1+new #add the character and string to this new new1="" #assigning empty string to new k=j else: new1=new1+(s[j]) #adding character to new new=s[k+1:]+new #adding substring to new reverse.append(new) #adding the reversed string to list print("After reversing:") for i in reverse: #printing all reversed strings print(i)
Output:
Please find the attached file.
Learn more:
brainly.com/question/20565175

