0% found this document useful (0 votes)
26 views2 pages

Question 2 Python Code

This Python code defines a function is_palindrome that checks if a given string is a palindrome by reversing the string and comparing it to the original, and a main function that prompts the user for input, calls is_palindrome, and prints the result.

Uploaded by

kang daniel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

Question 2 Python Code

This Python code defines a function is_palindrome that checks if a given string is a palindrome by reversing the string and comparing it to the original, and a main function that prompts the user for input, calls is_palindrome, and prints the result.

Uploaded by

kang daniel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

----------------------------------------------------------

Python code:-----

--------------------------------------------------------------

#!/usr/bin/python3 -tt

def is_palindrome(var2):

var3 = ""

for x in var2:

var3 = x + var3

if var3 == var2:

return True

else:

return False

def main():
print('Check a word, whether it is palindrome or not')

var1 = input('Enter a word: ')

var4 = is_palindrome(var1)

print('is_palindrome("{}") - {}'.format(var1, var4))

if __name__ == '__main__':

main()

You might also like