Python

Checks if something is a palindrome.

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.22918949566015567","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"cHJpbnQociIiIgogICBfX18gICAgICBfIF8gICAgICAgICAgIF8gICAgICAgICAgIAogIC8gXyBcX18gX3wgKF8pXyBfXyAgIF9ffCB8XyBfXyBfXyBfIAogLyAvXykvIF9gIHwgfCB8ICdfIFwgLyBfYCB8ICdfXy8gX2AgfAovIF9fXy8gKF98IHwgfCB8IHwgfCB8IChffCB8IHwgfCAoX3wgfApcLyAgICBcX18sX3xffF98X3wgfF98XF9fLF98X3wgIFxfXyxffAoKUGFsaW5kcm9tZSBkZXRlY3RvciAtIGJ5IEt6IiIiKQoKd2hpbGUgVHJ1ZToKCiAgICAjIGNhcHR1cmUKICAgIHRyeToKICAgICAgICBzdHJfaW5wdXQgPSBpbnB1dCgiXG5QbGVhc2UgZW50ZXIgeW91ciBwaHJhc2U6ICIpLmxvd2VyKCkKICAgIGV4Y2VwdCBLZXlib2FyZEludGVycnVwdDoKICAgICAgICBwcmludCgiXG5FbnRlciAnZXhpdCcgdG8gcXVpdC4iKQogICAgICAgIGNvbnRpbnVlCgogICAgIyBoYW5kbGUgZXhpdAogICAgZXhpdHMgPSBbImV4aXQiLCAicXVpdCIsICI6cSIsICI6ZSJdCiAgICBpZiBzdHJfaW5wdXQgaW4gZXhpdHM6CiAgICAgICAgcHJpbnQoIkJ5ZSBieWUhXG4iKQogICAgICAgIGV4aXQoKQoKICAgICMgY2xlYW4KICAgIHN0cl9jbGVhbmVkID0gIiIKICAgIGZvciBjaGFyIGluIHN0cl9pbnB1dDoKICAgICAgICBpZiBjaGFyLmlzYWxudW0oKToKICAgICAgICAgICAgc3RyX2NsZWFuZWQgKz0gY2hhcgoKICAgICMgbGVuZ2h0IHZhbGlkYXRpb24KICAgIHRvdGFsX2xlbiA9IGxlbihzdHJfY2xlYW5lZCkKICAgIGlmIHRvdGFsX2xlbiA8IDM6CiAgICAgICAgcHJpbnQoIlRvbyBzaG9ydCFcbiIpCiAgICAgICAgY29udGludWUKCiAgICBoYWx2ZV9sZW4gPSBpbnQodG90YWxfbGVuIC8gMikKICAgIHBhcnRfMSA9IHN0cl9jbGVhbmVkWzA6aGFsdmVfbGVuXQogICAgcGFydF8yID0gc3RyX2NsZWFuZWRbdG90YWxfbGVuLWhhbHZlX2xlbjpdCgogICAgIyByZXZlcnNlCiAgICBwYXJ0XzIgPSBwYXJ0XzJbOjotMV0KCiAgICBpZiBwYXJ0XzEgPT0gcGFydF8yOgogICAgICAgIHByaW50KCJUaGlzIGlzIGEgcGFsaW5kb21lISIpCiAgICBlbHNlOgogICAgICAgIHByaW50KCJOb29wLiIpCg=="},"asBuffer":null},"loaded":true}}
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
print(r"""
   ___      _ _           _           
  / _ \__ _| (_)_ __   __| |_ __ __ _ 
 / /_)/ _` | | | '_ \ / _` | '__/ _` |
/ ___/ (_| | | | | | | (_| | | | (_| |
\/    \__,_|_|_|_| |_|\__,_|_|  \__,_|

Palindrome detector - by Kz""")

while True:

    # capture
    try:
        str_input = input("\nPlease enter your phrase: ").lower()
    except KeyboardInterrupt:
        print("\nEnter 'exit' to quit.")
        continue

    # handle exit
    exits = ["exit", "quit", ":q", ":e"]
    if str_input in exits:
        print("Bye bye!\n")
        exit()

    # clean
    str_cleaned = ""
    for char in str_input:
        if char.isalnum():
            str_cleaned += char

    # lenght validation
    total_len = len(str_cleaned)
    if total_len < 3:
        print("Too short!\n")
        continue

    halve_len = int(total_len / 2)
    part_1 = str_cleaned[0:halve_len]
    part_2 = str_cleaned[total_len-halve_len:]

    # reverse
    part_2 = part_2[::-1]

    if part_1 == part_2:
        print("This is a palindome!")
    else:
        print("Noop.")