-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreverse_string.py
67 lines (50 loc) · 1.07 KB
/
reverse_string.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
Problem
-------
**Reverse a String**
Enter a string and the program
will reverse it and print it out.
Solution
--------
This problem is quite simple and
can be solved using the string as a list
and reverse it.
For visual way i kept a separate functions
but it's not necessary cause what you need
to reverse a string is about 6 character long
Author
------
dbonadiman
"""
import sys
def reverse(s):
"""
reverse
This function reverse a string it uses the same
approach used to manipulate lists
Parameters:
s==> the string to reverse
Test:
>>> reverse('ciao')
'oaic'
>>> reverse('oil')
'lio'
>>> reverse('')
''
"""
return s[::-1]
def main():
try:
print("\nThis program reverse a string\n"
"please enter the string you want to reverse: \n")
string = raw_input("-->")
print(reverse(string))
return 0
except Exception, e:
print(e)
return 1
if __name__ == "__main__":
import doctest
doctest.testmod()
status = main()
sys.exit(status)