-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse2.py
More file actions
23 lines (20 loc) · 711 Bytes
/
Copy pathreverse2.py
File metadata and controls
23 lines (20 loc) · 711 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def reverse(string : str) -> str:
'''
A function to reverse strings
'''
try:
#An empty string to store the reversed string
reversed_string : str = ''
#Checking for the length of the string
string_length : int = len(string)
#Looping through the string
for x in range(string_length):
#Concantenating the reversed letter to the reversed string
reversed_string += string[string_length-1]
#Looping downwardly through the letters
string_length -= 1
#Returning the reversed string
return reversed_string
except Exception as err:
print(f'{err}')
print(reverse('Great'))