Question

Example 1 : The program is to output a list elements in a specific format. To...

Example 1 :

The program is to output a list elements in a specific format.

To complete the program

* Create a module named h03_01.py from the directory hw

* Record your name, class number, and date of creation.

* Create a list contains the following shopping item: 'apples'

* Add three other items to the list: 'bananas', 'tofu', and 'milk'.

* Print list as a string with all the shopping items separated by a comma, a whitespace and a “and” before the last item: “apples, bananas, tofu, and milk”

Paste the captured screen here

0 0
Add a comment Improve this question Transcribed image text
Answer #1
shoppingItems = ['apple']

shoppingItems.append('bananas')
shoppingItems.append('tofu')
shoppingItems.append('milk')

print(', '.join(shoppingItems[0:-1]) + ', and ' + shoppingItems[-1])


Please upvote, as i have given the exact answer as asked in question. Still in case of any concerns in code, let me know in comments. Thanks!

Add a comment
Know the answer?
Add Answer to:
Example 1 : The program is to output a list elements in a specific format. To...
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