Write a program that checks whether two words are anagrams.
Two words are anagrams if they contain the same letters. For example, silent and listen are anagrams.
Code
def anagram(word1, word2):if sorted(word1) == sorted(word2):return Trueelse:return Falseif __name__ == "__main__":word1 = input("Enter first word: ")word2 = input("Enter second word: ")if anagram(word1, word2):print("Anagrams")else:print("Not anagrams")
Output
run the program and enter different words and check whether they are anagrams or not
0 Comments
Post a Comment