#This program tends to test for a palindrome iteratively. Please help find buG. def tester(): z = list('malyaylam') count = 0 for i in range(0, int(len(z)/2)+1): if z[i] == z[-i-1] and i <= int(len(z)/2): count += i if count == int(len(z)/2): print 'Congo u ve just found a Palindrome!' else: pass else: 'test failed!' tester()
1. "else: pass" is not necessary. 2. I think you have indentation problems with your second if and both else statements. 3. Add a bunch of print statements to make sure variables are doing what you think they're doing. 4. Reread each line carefully. One line in particular has a pretty obvious problem. Explain in words what you want the algorithm to do.
pls use a code pasting site to post your code, it makes it easier for us to comment. http://dpaste.com/641394/
fixed tester() , by changing count += i to count += 1. here's improved code: http://dpaste.com/641531/
#Palindrome Iterative Style. def listmaker(L): global z z = list(L) def caller(): global x x = raw_input('Enter the string for checking. ') listmaker(x) tester() def tester(): count = 0 for i in range(0, int(len(z)/2)+1): if z[i] == z[-i-1] and i <= int(len(z)/2): count += 1 if count == int(len(z)/2): print x, 'Is a Palindrome!' break else: print x, 'is not a palindrome...' caller()
Join our real-time social learning platform and learn together with your friends!