Exercise 52

Using Exercise 51, create a python program as a function which takes as a parameter a string s and which returns the same string in uppercase without using the upper() method. You can use the chr() and ord() methods.


def toUppercase(s):
# by using the exercise 51 we can obtain the lists of all upercase characters and lowercase characters:
uppercase_characters = [chr(i) for i in range(65 , 91)]
lowercase_characters = [chr(i) for i in range(97 , 122)]
# then we can obtain a uppercase charcter from lowercase character by by subtracting 32 to its ascii code

# initializing the searched string
s_upper = ""
for x in s:
if x in lowercase_characters:
x = chr(ord(x) -32)
s_upper = s_upper + x
s_upper = s_upper + x

return s_upper
print(toUppercase("Python Programming"))
# The output is : PYTHON PROGRAMMING

Younes Derfoufi
One thought on “Solution Exercise 52 : python code to transform given a string into uppercase”

Leave a Reply