Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python palindrome fuction

def is_palindrome(input_string):
	# Create two strings, to compare them
	new_string = ""
	reverse_string = ""
	# Traverse through each letter of the input string
	for x in range(len(input_string)):
    # This will give x the value of all the possible index numbers for each iteration
		# Add any non-blank letters to the 
		# end of one string, and to the front
		# of the other string. 
		if input_string[x] != " ":
			new_string += input_string[x]
			reverse_string = new_string[::-1]
	# Compare the strings
	if new_string.lower() == reverse_string.lower():
		return True
	return False
    
print(is_palindrome("Never Odd or Even")) # Should be True
Source by www.coursera.org #
 
PREVIOUS NEXT
Tagged: #python #palindrome #fuction
ADD COMMENT
Topic
Name
2+8 =