Question

python Two words are anagrams of each other if they contain the same letters in them....

python

Two words are anagrams of each other if they contain the same letters in them. So left is an anagram of felt and vice-versa. A Super Anagram is a special kind of anagram. A Super Anagram is an anagram whose first and last letters are the same.

Your program needs to read in two words on a single line. If the pair of words are Super Anagrams of each other, print out Super Anagram!. If the pair of words is not a Super Anagram (so a human couldn't read it), then print out Huh?. For one-letter words, the first letter is the last letter.

So, for example:

 
Enter words: brain brian
Super Anagram!
0 0
Add a comment Improve this question Transcribed image text
Answer #1
def is_anagram(str1,str2):
    #Converting to lower case
    str1 = str1.lower()
    str2 = str2.lower()
    i = 0
    while i<26:
        x = chr(97+i)
        #Checking the count of each alphabet(lower case) in each string
        if str1.count(x) != str2.count(x):
            return False
        i += 1
    return True

def is_super_anagram(str1,str2):
    if len(str1)==len(str2):
        if len(str1)==1:
            if str1==str2:
                return True
            else:
                return False
        else:
            if str1[0]==str2[0] and str1[-1]==str2[-1]:
                return is_anagram(str1[1:-1],str2[1:-1])
            else:
                return False
    else:
        return False

def main():
    s = input("Enter words: ").split(" ")
    word1 = s[0]
    word2 = s[1]
    if is_super_anagram(word1,word2):
        print("Super Anagram!")
    else:
        print("Not a Super Anagram!")

main()

Add a comment
Know the answer?
Add Answer to:
python Two words are anagrams of each other if they contain the same letters in them....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Two words or phrases in English are anagrams if their letters (and only their letters), rearranged,...

    Two words or phrases in English are anagrams if their letters (and only their letters), rearranged, are the same. We assume that upper and lower case are indistinguishable, and punctuation and spaces don't count. Two phrases are anagrams if they contain exactly the same number of exactly the same letters, e.g., 3 A's, 0 B's, 2 C's, and so forth. Some examples and non-examples of regular anagrams: * The eyes / they see (yes) * moo / mo (no) *...

  • # DISCUSSION SECTION WORK: # # 1. STUDENTS: download this file, ds4.py, and wordsMany.txt, from #...

    # DISCUSSION SECTION WORK: # # 1. STUDENTS: download this file, ds4.py, and wordsMany.txt, from # http://www.cs.uiowa.edu/~cremer/courses/cs1210/etc/ds4/ # Save both in the same folder. # # 2. TA (aloud) and STUDENTS: Read the comments from START HERE! (just after these instructions) # to definition of anagramInfo function. Discuss any questions about what the functions should do. # # 3. TA demonstrate running anagramInfo("wordsMany.txt") on this unchanged file, to # see that it behaves reasonably despite having incomplete anagram-testing functions. #...

  • Python Programming: An individual playing card is represented as a string of two characters: • the...

    Python Programming: An individual playing card is represented as a string of two characters: • the first character is from "23456789TJQKA" and represents the rank, i.e., the number or value of the card. (Note that 10 is encoded as letter T to make all card ranks to be single letters) • the second character is from "cdhs" and represents the suit (clubs, diamonds, hearts and spades respectively). For example, "Jd" would be the jack of diamonds, and "4s" would be...

  • Let us define the overlap between two words as the count of unique letters they have...

    Let us define the overlap between two words as the count of unique letters they have in common. Thus, the overlap between JANE and MICK is 0. Here are some more examples: - The overlap between JANE and MIKE is 1 (E is common) - The overlap between JANE and MEEK is 1 (E is common; we do not double count a letter) - The overlap between JANE and JEDI is 2 (J and E are common) - The overlap...

  • ** Language Used : Python ** PART 2 : Create a list of unique words This...

    ** Language Used : Python ** PART 2 : Create a list of unique words This part of the project involves creating a function that will manage a List of unique strings. The function is passed a string and a list as arguments. It passes a list back. The function to add a word to a List if word does not exist in the List. If the word does exist in the List, the function does nothing. Create a test...

  • Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The...

    Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The computer must select a word at random from the list of avail- able words that was provided in words.txt. The functions for loading the word list and selecting a random word have already been provided for you in ps3 hangman.py. 2. The game must be interactive; the flow of the game should go as follows: • At the start of the game, let the...

  • Hi I really need help with the methods for this lab for a computer science class....

    Hi I really need help with the methods for this lab for a computer science class. Thanks Main (WordTester - the application) is complete and only requires uncommenting to test the Word and Words classes as they are completed. The needed imports, class headings, method headings, and block comments are provided for the remaining classes. Javadocs are also provided for the Word and Words classes. Word The Word class represents a single word. It is immutable. You have been provided...

  • Using Python 3+ for Question P5.9 Instructions: Use one main() to call each of the functions...

    Using Python 3+ for Question P5.9 Instructions: Use one main() to call each of the functions you created. Only use one value of r and h for all the function. Ask the user for the r and h in the main() as an input, and h for all the functions. You should put the functions for areas in a separate file. ​ For example, firstDigtec7ze Write a function e digits n) (returning the number of digits in the argument returning...

  • Consider the two strings "doggie dish" and "Drip coffee". What letters do they have in common?...

    Consider the two strings "doggie dish" and "Drip coffee". What letters do they have in common? That is, what is the letter intersection count for the pair of strings? Let's look at 'd' first. The first string has 2 d's (d's occurrence count is 2), while the second has just 1 d (capitalization doesn't count) - so the intersection for the strings for d is 1. What about g? There the occurrence counts are 2 and 0, so the intersection...

  • ****************************************************************************************************************8 I want it same as the output and with details please and comments "For two...

    ****************************************************************************************************************8 I want it same as the output and with details please and comments "For two thousand years, codemakers have fought to preserve secrets while codebreakers have tried their best to reveal them." - taken from Code Book, The Evolution of Secrecy from Mary, Queen of Scots to Quantum Cryptography by Simon Singh. The idea for this machine problem came from this book.You will encrypt and decrypt some messages using a simplified version of a code in the book. The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT