AMS 209: HW 4: Problem 6ΒΆ

 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
#!/usr/bin/env python3
# coding: utf8

'''
Created on October 31st, 2017

@author: Geetanjali
'''

import math

def is_palindrome(word):
	"""
	:param word: the word to be tested if it is a palindrome
	:return flag: is set to True if word is a palindrome, else is set to False
	"""

	#We keep comparing the first and last letters in the word until we reach the middle.  
	for i in range(0, math.floor(len(word)/2)):
		if(word[i] == word[len(word)-1-i]):
			flag = True
		else:
			flag = False
			break

	return flag


if __name__ == '__main__':

	word = input("Enter word: ")
	print("Is the word you entered a palindrome? : "+str(is_palindrome(word)))