Question

Q4. Write a method called countCommon that takes 2 sentences and returns the number of letters that appear in both sentences.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Since no language is specified in the question Iam going to us python3 language

Cases considered:

Input : 2 sentences

Output:Number of letters common in both sentences

Therefore what i did is converting all the letters in both the sentences to lower case and chect whether the letters are present in both the sentences checking from a to z and returning tje count value

In my program the user can give the inputs for 2 sentences

Program:

def countCommon(sentence1,sentence2):
   test="abcdefghijklmnopqrstuvwxyz"
   sentence1.lower()
   sentence2.lower()
   count=int(0)
   for i in test:
       if((i in sentence1)&(i in sentence2)):
           count+=1
   return count


sentence1=input()
sentence2=input()

print(countCommon(sentence1,sentence2))

Add a comment
Know the answer?
Add Answer to:
Q4. Write a method called countCommon that takes 2 sentences and returns the number of letters...
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
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