10. Modify the list (3-6/3-7)

Source: Internet
Author: User

Tag: end eval person Val title cannot \ n Add/delete

3-6 Add guests: You just found a bigger dining table to accommodate more guests. Think about your invitation
Which three guests are invited.
? Add a print language at the end of the program based on the program written during Exercise 3-4 or exercise 3-5.
You have found a bigger table.
? USE insert () to add a new guest to the beginning of the list.

? USE insert () to add another new guest to the list.
? Use APPEND () to add the last new guest to the end of the list.
? Print a series of messages and send an invitation to each guest in the list.

Person_invited = ['Jim ', 'jack', 'Lucy'] print ("mr. Jim unable to attend !, I will invite Kate! \ N ") person_invited [0] = 'Kate 'print (person_invited) print (person_invited [0] +", I wowould like to invite you for dinner! ") Print (person_invited [1] +", I wowould like to invite you for dinner! ") Print (person_invited [2] +", I wowould like to invite you for dinner! ") Print (" \ n find a bigger table ") # Use Insert () to add a new guest to the beginning of the list. Person_invited.insert (0, 'valli') # Use Insert () to add another new guest to the list. person_invited.insert (2, 'eval') # Use APPEND () add the last new guest to the end of the list. Person_invited.append ('rain') for person in person_invited: Print ('invite, '+ person. Title () +' ')

3-7 drop-down list: You just know that the newly purchased table cannot be delivered in time, so you can only invite two guests.
? Based on the program written in the exercises 3-6, add a line of code at the end of the program and print one
We can invite two guests to dinner.
? Use Pop () to delete guests from the list until there are only two guests. Play from the list every time
When a guest is posted, a message is printed to let the guest know that you are sorry and cannot invite him to join us.
Dinner.
? For each of the remaining two guests, a message is printed, indicating that he is still invited.
? Use del to delete the last two guests from the list and leave the list empty. Print the list and verify the process
The list is indeed empty when the order ends.

Print ("\ n the newly purchased table cannot be delivered in time, so we can only invite two guests, sorry! ") N = Len (person_invited) while n> 2: person_pop = person_invited.pop (n-1) N-= 1 print (" not invited "+ person_pop.title () +", sorry! ") Print (person_invited)

  

  

10. Modify the list (3-6/3-7)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.