Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. import string
  2. russian = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ'
  3. again = True
  4.  
  5. class LengthError(Exception):
  6.     def __init__(self):
  7.         print('At least 2 characters are required')
  8.  
  9. class NumError(Exception):
  10.     def __init__(Self):
  11.         print('Numbers are not allowed')
  12.  
  13. while again == True:
  14.     try:
  15.         text = input('Your text goes here: ')
  16.         text = text.replace(" ","")
  17.         if len(text)<2:
  18.             raise LengthError
  19.         else:
  20.             for item in text:
  21.                 if item not in string.ascii_lowercase and item not in russian:
  22.                     raise NumError
  23.     except:
  24.         print('Try again')
  25.         pass
  26.     else:
  27.         if text == text[::-1]:
  28.             print('This is a palindrome')
  29.         else:
  30.             print("This isn't a palindrome")
  31.  
  32.         while True:
  33.             ask = input("Do you want to try again? y/n: ")
  34.             if ask == 'y':
  35.                 break
  36.             elif ask == 'n':
  37.                 again = False
  38.                 break
  39.             else:
  40.                 print('Invalid response')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement