forked from HarshCasper/NeoAlgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
anagram_checker.py
40 lines (27 loc) · 1.03 KB
/
anagram_checker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
This script takes two input strings and compare them to check if they are anagrams or not.
"""
def check_anagrams(first_string, second_string):
#If the length of both these words dont match then they cant be anagrams
if len(first_string) == len(second_string):
#Sort both the strings and check their equality
first_string = sorted(first_string.lower())
second_string = sorted(second_string.lower())
if first_string == second_string:
print("These two words are anagrams")
else:
print("These two words are not anagrams")
else:
print("These two words are not anagrams")
def main():
first_string = input("Enter a word: ")
second_string = input("Enter another one: ")
check_anagrams(first_string, second_string)
main()
#Sample Input-Output:
#Sample 1
#Inputs: "silent" and "listen"
#Output: These two words are anagrams
#Sample 2
#Inputs: "july" and "june"
#Output: These two words are not anagrams