• Register
1 vote
38 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?

10 7 2
6,060 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.

11 6 4
34,950 points

Related questions

0 votes
1 answer 3 views
3 views
Problem: how to I Solve this: check if two strings are anagrams python HELP! I need help understanding this: check if two strings are anagrams python Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 10 Mashhoodch 13k points
0 votes
1 answer 33 views
33 views
I am new to python programming.. I was trying to check if a string is empty or whitespace in a code : Mystr= "" Yourstr = " " print ("This string is empty : ", end = "") if(not Yourstr): print ("Yes") print ("This string is empty : ", end = "") if(not Mystr): print ("No") It’s output is : This string is empty : This string is empty : No Its not giving me actual result what can I do now?
asked Mar 16, 2020 LizzyM 6.1k points
0 votes
1 answer 25 views
25 views
I am new to python programming I was trying to check if a letter is uppercase in python. I wrote some code to check this statement : import string def UpperCase(s_str): for x in s_str: if x not in string.UpeerCase: return False return True But I can not get the actual ... last): File "<stdin>", line 1, in <module> NameError: name 'LoWWE' is not defined Can anyone help me to solve this thing?
asked Mar 14, 2020 LizzyM 6.1k points
0 votes
1 answer 106 views
106 views
I am new to python programming. I was trying to compare two strings, I wrote a code to compare: YourStr = "one" MyStr = "one" if YourStr = MyStr print("Two strings are same") else print("Two strings are not same") But it gives an error: File "main.py", line 4 if YourStr = MyStr ^ SyntaxError: invalid syntax Whats wrong in my code and how can I compare two string but it is not case sensitive?
asked Mar 16, 2020 LizzyM 6.1k points
1 vote
1 answer 2 views
2 views
Problem: Can someone please help fix this uncaught error : python check if two strings are equal
asked Mar 30 MUHAMMAD MUNEEB 80k points
0 votes
1 answer 3 views
3 views
Problem: anyone who know about this problem please help? python how to check if two strings are equal
asked Mar 18 Rohit kr 15k points
0 votes
1 answer 5 views
5 views
Problem: Need your help to solve this >'how to check if two strings are equal in python' ?
asked Mar 18 sadi1982 36.3k points
0 votes
1 answer 6 views
6 views
Problem I've been using the == operator in my program to compare all of my strings so far. However, I ran into an error, changed one of them to .equals () instead, and it fixed the error. Is == bad? When not to use? What is the difference?
asked Feb 7 ahmedadel9090 3.1k points
1 vote
1 answer 694 views
694 views
Problem: I am getting the following error : error: array initializer must be an initializer list or string literal For the array; char x[80] = GetString(); Can any body explain or help?
asked Apr 2, 2020 LizzyM 6.1k points
1 vote
1 answer 48 views
48 views
Problem: I am beginner in pyhton prgramming language, I tried to convert string array to int array using python so I wrote a code which contains- testing_list = ['4', '2', '3', '9', '5'] And my code is: testing_list = ['4', '2', '3', '9', '5 ... list is : str(testing_list) Converted list is : str(testing_list) why am I not getting the converted result and what is the way to get the acurate result?
asked Mar 29, 2020 LizzyM 6.1k points