@arcturus/Anagram Detector
Python3

No description

repl talk
Files
  • main.py
main.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
#defining the anagram function
def anagram():
    #ask the user for words to compare
    print('What two words would you like to compare and see if they are anagrams?')
    print('First word: ')
    word1 = str(input())
    print('Second word: ')
    word2 = str(input())
    #converts the strings from the user to uppercase
    word1Upper = word1.upper()
    word2Upper = word2.upper()
    #creation of empty lists for conversion from strings to lists
    word1u = []
    word2u = []
    #for loops do the work of making lists from the strings
    for char in word1Upper:
        word1u.append(char)

    for char in word2Upper:
        word2u.append(char)
    #sorting the letters into sequential order so that Python can compare the lists
    word1u = sorted(word1u)
    word2u = sorted(word2u)
    #condition that compares the sorted lists to each other to see if they match
    if word1u == word2u:
        #returns 1 if they match
       """ print('anagram')"""
       return 1
    else:
       """ print('not an anagram')"""
        #returns 0 if they don't
       return 0

    #print(word1u, word2u)
Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux