Computer Science
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)
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.
Related Questions
Zack is working in a database named SPORT, in which he has created a table named “Sports” containing columns SportId, SportName, no_of_players, and category. After creating the table, he realized that the attribute, category has to be deleted from the table and a new attribute TypeSport of data type string has to be added. This attribute TypeSport cannot be left blank. Help Zack write the commands to complete both the tasks.
Predict the output of the following code:
def Changer(P, Q = 10): P = P / Q Q = P % Q return P A = 200 B = 20 A = Changer(A, B) print(A, B, sep = '$') B = Changer(B) print(A, B, sep = '$', end = '###')
Consider the table CLUB given below and write the output of the SQL queries that follow.
CID CNAME AGE GENDER SPORTS PAY DOAPP 5246 AMRITA 35 FEMALE CHESS 900 2006-03-27 4687 SHYAM 37 MALE CRICKET 1300 2004-04-15 1245 MEENA 23 FEMALE VOLLEYBALL 1000 2007-06-18 1622 AMRIT 28 MALE KARATE 1000 2007-09-05 1256 AMINA 36 FEMALE CHESS 1100 2003-08-15 1720 MANJU 33 FEMALE KARATE 1250 2004-04-10 2321 VIRAT 35 MALE CRICKET 1050 2005-04-30 (i) SELECT COUNT(DISTINCT SPORTS) FROM CLUB;
(ii) SELECT CNAME, SPORTS FROM CLUB WHERE DOAPP<"2006-04-30" AND CNAME LIKE "%NA";
(iii) SELECT CNAME, AGE, PAY FROM CLUB WHERE GENDER = "MALE" AND PAY BETWEEN 1000 AND 1200;
Write a function in Python to read a text file, Alpha.txt and displays those lines which begin with the word ‘You’.