• Register
1 vote
50 views

Problem:

I am new in pyhton programing language . I was trying to check if two strings are anagrams python. But I fail repitedly. The code I wrote to check if two strings are anagrams is:
def IsAnagram(str1,str2):
    

str1 = input("Enter your first string : ")
str2 = input("Enter your secoend string : ")

if IsAnagram(str1,str2):
    print("Your first and secoend strings are anagram")
else:
    print("Your first and secoend strings are not anagram")

Which gives following error:

File "ppp.py", line 4
    str1 = input("Enter your first string : ")
    ^
IndentationError: expected an indented block

What is the problem can anyone tell?

6.1k points

Please log in or register to answer this question.

1 Answer

1 vote

Answer:

In pyhton if you define a class or function you have to return some of its value. So error is you did not return any value after defining a class or function.You should add:

return sorted(str1) == sorted(str2)

 This line after :

def IsAnagram(str1,str2):
    

This line

So your code should be like:

def IsAnagram(str1,str2):
    return sorted(str1) == sorted(str2)

str1 = input("Enter your first string : ")
str2 = input("Enter your secoend string : ")

if IsAnagram(str1,str2):
    print("Your first and secoend strings are anagram")
else:
    print("Your first and secoend strings are not anagram")

Happy coding.

35k points