In: Computer Science
Write a function which takes two words as string arguments and checks whether they are anagrams
NB: Please use spider in anaconda(python) and include a picture of the code
# function to check whether two strings are anagram
# of each other
def areAnagram(str1, str2):
# Get lengths of both strings
n1 = len(str1)
n2 = len(str2)
# If lenght of both strings is not same, then
# they cannot be anagram
if n1 != n2:
return 0
# Sort both strings
str1 = sorted(str1)
str2 = sorted(str2)
# Compare sorted strings
for i in range(0, n1):
if str1[i] != str2[i]:
return 0
return 1
# Driver code
str1 = input("Enter first string: ")
str2 = input("Enter second string: ")
# Function Call
if areAnagram(str1, str2):
print("\nThe two strings are anagram of each other")
else:
print("\nThe two strings are not anagram of each other")
PLEASE LIKE THE SOLUTION :))
IF YOU HAVE ANY DOUBTS PLEASE MENTION IN THE COMMENT