MCPcopy Create free account
hub / github.com/geekcomputers/Python / symmetry

Function symmetry

check whether the string is Symmetrical or Palindrome.py:22–45  ·  view source on GitHub ↗
(a)

Source from the content-addressed store, hash-verified

20
21
22def symmetry(a):
23 n = len(a)
24 flag = 0
25
26 if n % 2:
27 mid = n // 2 + 1
28 else:
29 mid = n // 2
30
31 start1 = 0
32 start2 = mid
33
34 while start1 < mid and start2 < n:
35 if a[start1] == a[start2]:
36 start1 = start1 + 1
37 start2 = start2 + 1
38 else:
39 flag = 1
40 break
41
42 if flag == 0:
43 print("The entered string is symmetrical")
44 else:
45 print("The entered string is not symmetrical")
46
47
48string = "amaama"

Calls

no outgoing calls

Tested by

no test coverage detected