## Sunday, October 18, 2020

Solution Exercise 52 : python code to transform given a string into uppercase

#### 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.

#### Solution

``````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
else:
s_upper = s_upper + x

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

Younes Derfoufi
my-courses.net

#### 1 comment:

1. I agree with a lot of the points you made in this article. If you are looking for the alteryx certification answers, then visit Analytics Fun. I appreciate the work you have put into this and hope you continue writing on this subject.