lowercase to uppercase in python
python program to get a String and convert the lower case characters to upper case Characters
Sample Input 1 :
Hello
Sample Output 1 :
HELLO
Program or Solution
s=input("Enter a String:")
result=""
for i in range(0,len(s)):
ascii_val = ord(s[i])
if(ascii_val>96 and ascii_val<123):
result+=chr(ascii_val-32)
else:
result+=chr(ascii_val)
s=result
print(s)
Program Explanation
unicode / ascii_val of lower case alphabets are from 97 to 122 unicode / ascii_val of upper case alphabets are from 65 to 90 so the difference between lower case and uppercase alphabets is 32.
use ord() method to find ascii_val of a character.
Use chr() method to find character of ascii value Note: String is immutable, so you cannot modify a character directly in a orginal string.