Question

Mad Libs are activities that have a person provide various words, which are then used to...

Mad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (and hopefully funny) ways.

Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is quit 0.

# in python

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

#code

def main():
    #reading a line of text and splitting by white space to create a list of two tokens
    fields=input().split(' ')
    #looping until the first word is 'quit' in any case
    while fields[0].lower()!='quit':
        #displaying in the format 'Eating   a day keeps the doctor away.'
        #assuming that there will always be 2 values in input string separated by space
        print('Eating {} {} a day keeps the doctor away.'.format(fields[1],fields[0]))
        # reading next line of text and splitting by white space
        fields = input().split(' ')

#invoking main() method
main()

#output (user input in green text)

Add a comment
Know the answer?
Add Answer to:
Mad Libs are activities that have a person provide various words, which are then used to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

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