Class - 12 CBSE Computer Science Important Output Questions 2025
Predict the output of the Python code given below:
Text1 = "IND-23"
Text2 = ""
I = 0
while I < len(Text1):
if Text1[I] >= "0" and Text1[I] <= "9":
Val = int(Text1[I])
Val = Val + 1
Text2 = Text2 + str(Val)
elif Text1[I] >= "A" and Text1[I] <= "Z":
Text2 = Text2 + (Text1[I + 1])
else:
Text2 = Text2 + "*"
I += 1
print(Text2)
Python
Python String Manipulation
3 Likes
Answer
ND-*34
Working
The provided Python code initializes a variable Text1
with the string value "IND-23". Then it initializes an empty string variable Text2
and an index variable I
with the value 0. The while loop continues as long as I
is less than the length of Text1
. Within the loop, each character of Text1
is checked: if it's a digit (0-9), it increments the digit by 1 and appends it to Text2
; if it's an uppercase letter (A-Z), it appends the next character in Text1
to Text2
; otherwise, it appends an asterisk "*". After processing all characters, the final value of Text2
is printed.
Answered By
1 Like