Check if a string is palindrome Dry Run in PYTHON

Check if a string is palindrome is an interactive PYTHON dry run visualizer from the For programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Check if a string is palindrome Program Code

# Check if a string is palindrome
text = input("Enter a string: ")

# Convert to lowercase for case-insensitive comparison
text_lower = text.lower()

# Remove spaces for multi-word phrases
clean_text = text_lower.replace(" ", "")

is_palindrome = True
length = len(clean_text)

for i in range(length // 2):
    if clean_text[i] != clean_text[length - 1 - i]:
        is_palindrome = False
        break

if is_palindrome:
    print(f'"{text}" is a palindrome')
else:
    print(f'"{text}" is NOT a palindrome')

View the complete For programs page.

Program Console Check if a string is palindrome Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.