Test Index
Python Revision Tour
© examsnet.com
Question : 65 of 102
Marks:
+1,
-0
Write the output on execution of the following 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()
[CBSE 2024 Set 4]
Solution:
Output:
R*A*C*E*C*A*R*C#a#r#R*A*D*A*R*Explanation:
L = ['Racecar', 'Car', 'Radar']Racecar: x = RACECAR, which is the same reversed (palindrome), so each letter of x (upper case) is printed with *.Car: x = CAR, reversed RAC, not a palindrome, so each letter of the original word W (Car) is printed with #.Radar: x = RADAR, a palindrome, so R*A*D*A*R*.The print() after each word moves to a new line.© examsnet.com
Go to Question: