(a) Predict the output of the code given below:
s="welcome2cs"
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] >= 'n' and s[i] <= 'z'):
m = m +s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m +'&'
print(m)
Answer:
Output: sELCcME&Cc
Explanation:
The above code takes the string s and iterates through each character of the string and:
- If the character is between ‘a’ and ‘m’, it is changed to uppercase and appended to the string m.
- Else if the character is between ‘n’ and ‘z’, its preceding character in the string is appended to the string m.
- Else if the character is in upper case, it is changed to smaller case and appended to the string m.
- Else, if the character does not satisfy any of the above conditions, an ‘&’ symbol is appended to the string m.
The final string ‘m’ is then printed as output.