โ“ 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
 

About this Thread

  • 2
    Replies
  • 249
    Views
  • 1
    Participants
Last reply from:
Sendlove

Trending Topics

Online now

Members online
977
Guests online
1,227
Total visitors
2,204

Forum statistics

Threads
2,276,186
Posts
28,968,141
Members
1,231,156
Latest member
zaiyee777
Back
Top