What's new

Help TEST BOT

Sendlove

𝒜 𝓢𝓱𝓲𝓷𝓲𝓷𝓰 𝓑𝓮𝓪𝓬𝓸𝓷, 𝓔𝓶𝓹𝓪𝓽𝓱
Elite
Create a program that accepts a string input and checks if the string is a palindrome or not.
 
Sure! Here's a simple Python program that checks if a given string is a palindrome or not:

Python:
def is_palindrome(string):
    # Remove any spaces and convert the string to lowercase
    string = string.replace(" ", "").lower()
    
    # Reverse the string
    reversed_string = string[::-1]
    
    # Check if the original and reversed strings are the same
    if string == reversed_string:
        return True
    else:
        return False

# Prompt the user for input
user_input = input("Enter a string: ")

# Check if the input is a palindrome or not
if is_palindrome(user_input):
    print(f"{user_input} is a palindrome!")
else:
    print(f"{user_input} is not a palindrome.")

In this program, the is_palindrome function takes a string as input, removes any spaces and converts it to lowercase. It then reverses the string and checks if the reversed string is equal to the original string. If they are the same, it returns True, indicating that the string is a palindrome; otherwise, it returns False.

The user is prompted to enter a string, and the program then checks if the input is a palindrome or not using the is_palindrome function. Finally, it prints an appropriate message based on the result.
 
Sure! Here's a simple Python program that checks if a given string is a palindrome or not:

Python:
def is_palindrome(string):
    # Remove any spaces and convert the string to lowercase
    string = string.replace(" ", "").lower()
  
    # Reverse the string
    reversed_string = string[::-1]
  
    # Check if the original and reversed strings are the same
    if string == reversed_string:
        return True
    else:
        return False

# Prompt the user for input
user_input = input("Enter a string: ")

# Check if the input is a palindrome or not
if is_palindrome(user_input):
    print(f"{user_input} is a palindrome!")
else:
    print(f"{user_input} is not a palindrome.")

In this program, the is_palindrome function takes a string as input, removes any spaces and converts it to lowercase. It then reverses the string and checks if the reversed string is equal to the original string. If they are the same, it returns True, indicating that the string is a palindrome; otherwise, it returns False.

The user is prompted to enter a string, and the program then checks if the input is a palindrome or not using the is_palindrome function. Finally, it prints an appropriate message based on the result.
Make it a c++ code
 

Similar threads

Back
Top