AndreiL
Welcome to AndreiL.
Enjoy your time.
Please log in.

Checking for palindrome from file - Python

Go down

Checking for palindrome from file - Python

Post by Lucaci Andrei on Mon Feb 20, 2012 1:32 am

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
'''
Created on Feb 20, 2012

@author: sin
'''
def lff(file):
line = open(file).read().splitlines()
for i in range(0, len(line)):
if str(line[i]).lower() == str(line[i]).lower()[::-1]:
print "'" + str(line[i]) + "'", "is palindrome."
else:
print "'" + str(line[i]) + "'", "is not palindrome."

file = str(raw_input("Filename: ")) + str('.txt')
if __name__ == "__main__":
lff(file)


Checks, from a given file.txt, with 1 word on the line, if that word is a palindrome.
If it is, it will print a message saying it is, otherwise saying it isn't.
Note that when you are inserting the name of the file, don't use the termination .txt, it will automatically be included by this instruction:

14
file = str(raw_input("Filename: ")) + '.txt'

avatar
Lucaci Andrei
"Tata Lor"


Number of messages : 222
Points : 2266743
Reputation : 1007
Registration date : 2008-08-15
Age : 26
Location : Cluj-Napoca

View user profile http://www.andreil.wgz.ro

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum