-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from Cyber-Mukherjee/main
Create check_Palindrome.py
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
def isPalindrome(str,rev_str): | ||
x = str == rev_str | ||
return x | ||
|
||
while True: | ||
try: | ||
choice = int(input("Press the number corresponding to the option to select it\n0.\tExit\n1.\tCheck for Palindrome\n")) | ||
|
||
if choice == 1: | ||
string = input("Enter the string you want to check: ") | ||
low_str = string.lower() | ||
rev_str = low_str[-1::-1] | ||
|
||
result = isPalindrome(low_str,rev_str) | ||
if result == True: | ||
print(f"\n{string} is a palindrome!") | ||
elif result == False: | ||
print(f"\n{string} is not a palindrome as it spells {rev_str} when reversed.") | ||
else: | ||
print("invalid input") | ||
|
||
elif choice == 0: | ||
print("\n####################\tThank you for using my program\t####################") | ||
break | ||
else: | ||
print("\nInvalid input") | ||
|
||
except: | ||
print("\nEnter an integer value corresponding to your choice!") | ||
|