Question

Implement a program that requests from the user a list of words (i.e., strings) and then...

Implement a program that requests from the user a list of words (i.e., strings) and then prints on the screen, one per line, all four-letter strings in the list.

>>> Enter word list: ['stop', 'desktop', 'top', 'post']

stop

post

An acronym is a word formed by taking the first letters of the words in a phrase and then making a word from them. For example, RAM is an acronym for random access memory.

Write a function acronym() that takes a phrase (i.e., a string) as input and then returns the acronym for that phrase.

Note: The acronym should be all uppercase, even if the words in the phrase are not capitalized.

>>> acronym('Random access memory')

'RAM'

>>> acronym('central processing unit')

'CPU'

  1. Define a class called Animal that abstracts animals and supports three methods:
  • setSpecies(species): Sets the species of the animal object to species.
  • setLanguage(language): Sets the language of the animal object to language.
  • speak(): Prints a message from the animal as shown below.

The class must support supports a two, one, or no input argument constructor.

Then define Bird as a subclass of Animal and change the behavior of method speak() in class Bird.

>>> snoopy = Animal('dog', 'bark')

>>> snoopy.speak()

I am a dog and I bark.

>>> tweety = Animal('canary')

>>> tweety.speak()

I am a canary and I make sounds.

>>> animal = Animal()

>>> animal.speak()

I am a animal and I make sounds.

>>> daffy = Bird()

>>> daffy.speak()

quack! quack! quack!

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

strnew =input("Enter word list:")
list = strnew.split (",")
for i in list:
if(len(i)==4):
print(i)
  

Expected output:

def acronym(phrase):
listwrds=phrase.split(' ');
stri="";
for i in listwrds:
stri+=(i.upper())[0];
  
return stri;
  
print(acronym('Random access memory'))
print(acronym('Central processing unit'))

Expected output:

class Animal:

def __init__(self,species="animal",language="make sounds"):
self.__species=species;
self.__language=language;
  
  
  
  
def setSpecies(self,species):
self.__species=species;
  
def setLanguage(self,language):
self.__language=language;
  
def speak(self):
print('I am a '+self.__species+" and I "+self.__language);
  
class Bird(Animal):
  
def speak(self):
print("quack! quack! quack!");
  
snoopy = Animal('dog', 'bark');
snoopy.speak();
tweety = Animal('canary');
tweety.speak();
animal = Animal();
animal.speak();
daffy = Bird();
daffy.speak();

Expected output:

Add a comment
Know the answer?
Add Answer to:
Implement a program that requests from the user a list of words (i.e., strings) and then...
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