हिंदी

Write the output on execution Python code: S="Racecar Car Radar" L=S.split() for W in L: x=W upper() if x==x [: :-1]: for I in x: print (I, end="*") else: for I in W: print (I, end="#") print()

Advertisements

प्रश्न

Write the output on execution Python code:

S="Racecar Car Radar" 
L=S.split() 
for W in L: 
     x=W upper() 
     if x==x [: :-1]: 
          for I in x:  
               print (I, end="*") 
     else: 
          for I in W: 
                print (I, end="#") 
print() 
लघु उत्तरीय
Advertisements

उत्तर

Output:

R*A*C*E*C*A*R*
C#a#r#
R*A*D*A*R*

Explanation: The sentence is divided into a list of words L by the code. Every word in the list is selected by the loop, which then changes it to uppercase and compares it to its reverse. If both are the same, the word's characters are printed with a "*" between them. If the selected word is not a palindrome, '#' is used to separate the word's letters.

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2023-2024 (March) Set 4
Advertisements
Share
Notifications



      Forgot password?
Use app×