Question

In: Computer Science

Assignment 3-4: IN PYTHON Guest List: If you could invite anyone to dinner, who would you...

Assignment 3-4: IN PYTHON

Guest List: If you could invite anyone to dinner, who would you invite? Make a list that includes at least three people you’d like to invite to dinner. Then use your list to print a message to each person, inviting them to dinner.

---------------------------------------------------------------

Assignment 3-5:

Changing Guest List: You just heard that one of your guests can’t make the dinner, so you need to send out a new set of invitations. You’ll have to think of someone else to invite.

  • Start with your program from Assignment 3-4. Add a print statement at the end of your program stating the name of the guest who can’t make it.
  • Modify your list, replacing the name of the guest who can’t make it with the name of the new person you are inviting.
  • Print a second set of invitation messages, one for each person who is still in your list.

---------------------------------------------------------------

Assignment 3-6:

More Guests: You just found a bigger dinner table, so now more space is available. Think of three more guests to invite to dinner.

  • Start with your program from Assignment 3-4 or Assignment 3-5. Add a print statement to the end of your program informing people that you found a bigger dinner table.
  • Use insert() to add one new guest to the beginning of your list.
  • Use insert() to add one new guest to the middle of your list.
  • Use append() to add one new guest to the end of your list.
  • Print a new set of invitation messages, one for each person in your list.

---------------------------------------------------------------

Assignment 3-7:

Shrinking Guest List: You just found out that your new dinner table won’t arrive in time for the dinner, and you have space for only two guests.

  • Start with your program from Assignment 3-6. Add a new line that prints a message saying that you can invite only two people for dinner.
  • 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.
  • Print a message to each of the two people still on your list, letting them know they’re 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.

PreviousNext

Solutions

Expert Solution

Thanks for the question.

Here is the completed code for this problem. 

Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. 

If you are satisfied with the solution, please rate the answer. 

Thanks

===========================================================================

# assignment 3-4
invited=['Obama','Trump','Diana']

for person in invited:
    print('Hello {}, I am pleased to invite you for dinner.'.format(person))

# assignment 3 -5
print('Trump is busy. He can\'t come for dinner')
index_trump=invited.index('Trump')
invited[index_trump]='Queen Elizabeth'
for person in invited:
    print('Hello {}, I am pleased to invite you for dinner.'.format(person))

# assignment 3-6

invited.insert(0,'Enya') # add to the front
invited.insert(len(invited)//2,'Donna') # add to the middle
invited.append('Marsha') # add to the end
for person in invited:
    print('Hello {}, I am pleased to invite you for dinner.'.format(person))

# assignment 3-7

while len(invited)!=2:
    name=invited.pop()
    print('I am sorry {}, we can\'t invite you for dinner.'.format(name))
#Use del to remove the last two names from your list, so you have an empty list
del invited[-1]
del invited[-1]
#Print your list to make sure you actually have an empty list at the end of your program.
for person in invited:
    print('Hello {}, I am pleased to invite you for dinner.'.format(person))


Related Solutions

Micro in the Clinic -- An Uninvited Dinner Guest? -------------------------------------------- Marcella is a 43-year-old woman who...
Micro in the Clinic -- An Uninvited Dinner Guest? -------------------------------------------- Marcella is a 43-year-old woman who has been working hard toward getting healthy and fit. Over the last year, she has been eating more fresh fruits and vegetables and has been working out regularly six days a week. She has also been working out regularly six days a week. She has also committed herself to buying her fruits and vegetables from her local farmer's market. While she likes the fresh...
You have 10 friends: 3 couples and 4 singles. How many ways can you invite 7...
You have 10 friends: 3 couples and 4 singles. How many ways can you invite 7 of them to your house, such that the two people of every couple are either both invited or not?
Question 4 The list of all means you would compute from all possible samples you could...
Question 4 The list of all means you would compute from all possible samples you could draw of a given size from a given population is called the: Standard Error of the Mean Confidence Level Sampling Distribution of Means Confidence Interval Question 5 The larger the sample size, the _______ the standard error of the mean. larger smaller more dispersed. less dispersed. What does the central limits theorem tell us about the mean of the sampling distribution of means? The...
Python 3 question Suppose that a directed and weighted graph represented as vertex-list, how could it...
Python 3 question Suppose that a directed and weighted graph represented as vertex-list, how could it perform uniform cost search by using priority queue?
Can anyone use python to solve this problem: Part B: List of lists The aim of...
Can anyone use python to solve this problem: Part B: List of lists The aim of Part B is to learn to work with list of lists. You may want to open the file lab05b_prelim.py in the editor so that you can follow the task description. The first part of the file lab05b_prelim.py defines a variable called datasets. The variable datasets is a list of 4 lists. This part consists of 2 tasks. Task 1: We ask you to type...
4 strategies you would implement to support children who are 3/4 years of age attention span...
4 strategies you would implement to support children who are 3/4 years of age attention span development in the classroom. 2 paragraphs for each strategy
for Python 3 Write a python program that Creates a list that has these values in...
for Python 3 Write a python program that Creates a list that has these values in this order, 'Python', 'JavaScript', and 'PHP' Define a displayMyClasses function that sorts the list and then displays each item on the list, one per line, in sorted order. Also, number the displayed list as shown in the "Running a Sample Program" shown below. Define a guessNext function that selects a random element from the list and returns it to the call of the function....
For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
Write a Python program that has a list of 5 numbers [2, 3, 4, 5, 6)....
Write a Python program that has a list of 5 numbers [2, 3, 4, 5, 6). Print the first 3 elements from the list using slice expression. a. Extend this program in a manner that the elements in the list are changed to (6, 9, 12, 15, 18) that means each element is times 3 of the previous value. b. Extend your program to display the min and max value in the list.
In this PYTHON 3 program assignment, you will find a text file named WorldSeries.txt. This file...
In this PYTHON 3 program assignment, you will find a text file named WorldSeries.txt. This file contains a chronological list of the World Series' winning teams from 1903 through 2018. The first line in the file is the name of the team that won in 1903, and the last line is the name of the team that won in 2018. (Note the World Series was not played in 1904 and 1994. There are entries in the file indicating this.) Write...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT