Print a new set of invitation messages, one for each person in your list.
persons = ['ujala','taqi','malik'] new_persons = ['shah','asad','unknown'] persons.extend(new_persons)print(f"Hello {persons[0]} you are invited. Please come with you other team member {persons[1]}. Hello {persons[2]} you are also cordially invited.")
Hello ujala you are invited. Please come with you other team member taqi. Hello malik you are also cordially invited.
Exercise 3-7 Shrinking Guest List:
Start with your program from Exercise 3-6. Add a new line that prints a message saying that you can invite only two people for dinner.
# Here it will remove last guest from the listpersons.pop() f"{persons}"# Lets remove multiple guests since we have only 2 guests allowed now.persons.remove("taqi") f"{persons}"# lets remove all guests except first 2persons = persons[:2] f"{persons}"f"We have problem due to table availablity. We can invite only {','.join(persons)} now"
"['ujala', 'malik']We have problem due to table availablity. We can invite only ujala,malik now"
Use pop() to remove guests from your list one at a time until only two names remain in your list. Each time you pop a name from your list, print a message to that person letting them know you’re sorry you can’t invite them to dinner.
# we have already completed this exercise above through indexing. Now we will print required msg persons = ['ujala','taqi','malik'] f"{persons.pop().title()}, we are sorry we can't invite you"
"Malik, we are sorry we can't invite you"
Print a message to each of the two people still on your list, letting them know they’re still invited.
persons = persons.pop() f"{','.join(persons).title()}, you are still invited"
'T,A,Q,I, you are still invited'
Use del to remove the last two names from your list, so you have an empty list. Print your list to make sure you actually have an empty list at the end of your program.
persons = ['ujala','taqi','malik'] del persons[:]persons
[]
Exercise 3-8 Seeing the World:
Think of at least five places in the world you’d like to visit.
Store the location in a list and make sure list in not alphabatical order
locations = ['lahore','islamabad','karachi','fsd','rawalpindi']# printing list as rawlocations