-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise34.py
More file actions
38 lines (26 loc) · 787 Bytes
/
Copy pathExercise34.py
File metadata and controls
38 lines (26 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def getUppercase(text: str) -> str:
"""
Return a uppercase of the text
:param text: text in string
:type text: str
:raise TypeError: If text is not a str
:return: str
:rtype: str
"""
upperCase = ""
if len(text) == 0:
return upperCase
for i in range(len(text)):
if 97 <= ord(text[i]) <= 122:
upperCase += chr(ord(text[i]) - 32)
else:
upperCase += text[i]
return upperCase
...
assert getUppercase("Hello") == "HELLO"
assert getUppercase("hello") == "HELLO"
assert getUppercase("HELLO") == "HELLO"
assert getUppercase("Hello, world!") == "HELLO, WORLD!"
assert getUppercase("goodbye 123!") == "GOODBYE 123!"
assert getUppercase("12345") == "12345"
assert getUppercase("") == ""