Python Program to Find Anagram

Sure, here’s a Python program to find anagrams:

# function to check if two strings are anagrams
def check_anagram(str1, str2):
    # convert both strings to lowercase
    str1 = str1.lower()
    str2 = str2.lower()
    
    # check if the lengths of the strings are equal
    if len(str1) != len(str2):
        return False
    
    # sort both strings alphabetically
    sorted_str1 = sorted(str1)
    sorted_str2 = sorted(str2)
    
    # check if the sorted strings are equal
    if sorted_str1 == sorted_str2:
        return True
    else:
        return False

# main program
string1 = input("Enter the first string: ")
string2 = input("Enter the second string: ")

if check_anagram(string1, string2):
    print("The strings are anagrams.")
else:
    print("The strings are not anagrams.")

This program defines a function check_anagram that takes two strings as arguments and returns True if the strings are anagrams and False otherwise. The function converts both strings to lowercase, checks if their lengths are equal, and then sorts them alphabetically. If the sorted strings are equal, the function returns True. Otherwise, it returns False.

In the main program, the user is prompted to enter two strings. The check_anagram function is called with these strings as arguments. If the function returns True, the program prints “The strings are anagrams.” If the function returns False, the program prints “The strings are not anagrams.”

What is Anagram?:

An anagram is a word or phrase formed by rearranging the letters of another word or phrase. For example, the word “listen” can be rearranged to form the word “silent”, which is an anagram of “listen”. Anagrams can be formed by rearranging all the letters in a word or phrase or just some of the letters. Anagrams are often used in word games and puzzles.

Example of Anagram Program in Python:

Sure, here’s an example of an anagram program in Python:

def check_anagram(str1, str2):
    # convert both strings to lowercase
    str1 = str1.lower()
    str2 = str2.lower()

    # remove all whitespaces from the strings
    str1 = str1.replace(" ", "")
    str2 = str2.replace(" ", "")

    # sort both strings alphabetically
    sorted_str1 = sorted(str1)
    sorted_str2 = sorted(str2)

    # check if the sorted strings are equal
    if sorted_str1 == sorted_str2:
        return True
    else:
        return False

# main program
string1 = input("Enter the first string: ")
string2 = input("Enter the second string: ")

if check_anagram(string1, string2):
    print("The strings are anagrams.")
else:
    print("The strings are not anagrams.")

This program defines a function check_anagram that takes two strings as arguments and returns True if the strings are anagrams and False otherwise. The function converts both strings to lowercase, removes all whitespaces from the strings, and then sorts them alphabetically. If the sorted strings are equal, the function returns True. Otherwise, it returns False.

In the main program, the user is prompted to enter two strings. The check_anagram function is called with these strings as arguments. If the function returns True, the program prints “The strings are anagrams.” If the function returns False, the program prints “The strings are not anagrams.”