“Incredible India!” is a popular promotional slogan used by the Tourism…
2026
“Incredible India!” is a popular promotional slogan used by the Tourism Department. The following Python program generates an encrypted version of the slogan. Carefully analyze the given Python program and determine the outputs produced at different stages of program execution.
Original = "Incredible India!"
print(Original) # Output A1
Original = Original.strip("!")
print(Original) # Output A2
Encrypted = ""
Temp = ""
for Ch in Original:
if Ch.isupper():
Temp += Ch.lower()
else:
Temp += Ch.upper()
print(Temp) # Output B
Encrypted = Temp
Temp = ""
for i in range(1, len(Encrypted), 2):
Temp += Encrypted[i] + Encrypted[i-1]
print(Temp) # Output C
if len(Encrypted) % 2 != 0:
Temp += Encrypted[-1]
Encrypted = Temp
print(Encrypted) # Output D(A) What will be the outputs of the print statements marked Output A1 and Output A2?
(B) What will be the output marked Output B?
(C) What will be the output marked Output C?
(D) What will be the output marked Output D?
Show answer & explanation
(A) Outputs A1 and A2:
Original starts as:
Incredible India!
Output A1:
Incredible India!
The statement Original = Original.strip("!") removes the exclamation mark from the beginning/end if present. Here the exclamation mark at the end is removed.
Output A2:
Incredible India
(B) Output B:
The case of each character in the stripped string is toggled.
Incredible India -> iNCREDIBLE iNDIA
Output B:
iNCREDIBLE iNDIA
(C) Output C:
Encrypted is iNCREDIBLE iNDIA. The loop swaps adjacent pairs:
(i,N) -> Ni, (C,R) -> RC, (E,D) -> DE, (I,B) -> BI, (L,E) -> EL, (space,i) -> i(space), (N,D) -> DN, (I,A) -> AI
Output C:
NiRCDEBIELi DNAI
(D) Output D:
The length of Encrypted is 16, which is even. Therefore len(Encrypted) % 2 != 0 is False, so no extra character is appended.
Output D:
NiRCDEBIELi DNAI