Test Index
Python Revision Tour
© examsnet.com
Question : 76 of 102
Marks:
+1,
-0
Predict the output of the Python code given below :
s="India Growing"n = len(s)m=""for i in range (0, n) : if (s[i] >= 'a' and s[i] <= 'm') : m = m + s [i].upper() elif (s[i] >= 'O' and s[i] <= 'z') : m = m +s [i-1] elif (s[i].isupper()): m = m + s[i].lower() else: m = m + '@'print (m)
[CBSE 2024 Compartment]
Solution:
Concept:Characters are compared by their ASCII/Unicode values: 'A'-'Z' are 65-90, 'a'-'z' are 97-122, space is 32. So
Output:
'O' <= ch <= 'z' is true for 'O'-'Z', a few symbols, and all lowercase letters; since 'a'-'m' are already caught by the first test, the second test catches 'n'-'z' (and uppercase 'O'-'Z').Explanation: s = "India Growing", n = 13| i | s[i] | Branch | Added |
| 0 | I | uppercase, before O | i |
| 1 | n | 'O' to 'z': add s[0] | I |
| 2 | d | 'a' to 'm': upper | D |
| 3 | i | 'a' to 'm': upper | I |
| 4 | a | 'a' to 'm': upper | A |
| 5 | (space) | else | @ |
| 6 | G | uppercase, before O | g |
| 7 | r | 'O' to 'z': add s[6] | G |
| 8 | o | 'O' to 'z': add s[7] | r |
| 9 | w | 'O' to 'z': add s[8] | o |
| 10 | i | 'a' to 'm': upper | I |
| 11 | n | 'O' to 'z': add s[10] | i |
| 12 | g | 'a' to 'm': upper | G |
iIDIA@gGroIiG
© examsnet.com
Go to Question: