Python palindrome programming -
the code bit messy, point divide different functions.
i understand can test palindrome how use boolean variable, instead of stating straight away print function.
def trial(): palindrome = true c = str(input("hey: ")) in range(len(c)): = c[i] s = c[-(i+1)] if (a == s): return break else: print ("no, not plaindrome") break return palindrom def output(): print true trial() output()
you can use return
value within function
def ispalindrome(s): return s == s[::-1] def output(s): if ispalindrome(s): # use return value of above function print('it palindrome') else: print('not palindrome')
for example
>>> output('hello') not palindrome >>> output('abcba') palindrome
Comments
Post a Comment