I was wondering how I could completely upper case a string without the use of any functions involving .upper()? Is there a way to possibly capitalize with the ord() function? I am in an exercise where I must refrain from using the .upper function.
2 Answers
ord("A") --> 65 ord("B") --> 66 ...
ord("a") --> 97 ord("b") --> 98 ...
So whenever you want to change lowercase character to uppercase without using upper() function, you can just find the ASCII value of lowercase using ord() function, subtract 32 (which is the difference between uppercase and lowercase) and then use chr() function to convert it back to char.
print ('Case changer(Capital to small ONLY)')
line1 = input ('Enter here: ')
g = ""
for ch in line1:
if ord (ch) >= 65 and ord(ch) <= 90:
x = ord(ch) + 32
y = chr (x)
g = g + y
print(g)
-
Although this code may be help to solve the problem, providing additional context regarding why and/or how it answers the question would significantly improve its long-term value. Please edit your answer to add some explanation. Jul 7, 2016 at 17:02
ord('a') - ord('A')
in IDLE.