Question

In: Computer Science

Not sure how to prompt these functions here. I am trying tocreate a holiday shopping...

Not sure how to prompt these functions here. I am trying to create a holiday shopping list. Here are my three requirements

'''

This function should prompt the user for the names of all the family members that they will be purchasing gifts for this holiday and return those names in a list

'''

def family_names():

names = []

return names

'''

This function takes the names of all family members as a list and asks the user how much money they will spend on each person. These values are stored in a NEW list and returned.

'''

def spend(family):

pass

'''

This function takes two lists as parameters, one that has the names of all family members and a second that has how much was spent on each family member. The function calculates which family member is getting the most expensive gift and prints to the screen. Who this person is and how much is being spent on them. This function does not return anything.

'''

def favorite(family,gifts):

pass

#-----main-----

people = family_names()

money = spend(people)

favorite(people,money)

Solutions

Expert Solution

# program to create functions for holiday shopping list

# this function prompts for all the names
def family_names():
   names = [] # empty list
   while True:
       entry = input ("Enter name: ")
       names.append(entry)
       while True:
           choice = input("Do you want to add more names? (Y/N): ").upper()
           if choice == "Y" or choice == "N":
               break

       # if N is entered, stop taking new names
       if choice == "N":
           break
   return names


# this function stores how much to spend in a new list
def spend(family):
   # create empty list
   budget = []
   for member in family:
       money = float(input ("How much do you want to spend for {0}: ".format(member)))
       budget.append(money)
   return budget

# prints details
def favorite(family, gifts):
   favorite = -1 # index position of the favorite family member
   maxspent = -1 # default maximum spent yet
   for i in range (0, len(gifts)):
       if gifts[i] > maxspent:
           maxspent = gifts[i]
           favorite = i # update index position of favorite member
   # print the result
   print ("Favorite family member is {0}.".format(family[favorite]))
   print ("Amount spent on them is {0}\n".format(gifts[favorite]))

# main
if __name__ == "__main__":
   people = family_names()
   money = spend(people)
   favorite(people, money)

Screenshot of the code:

OUTPUT:


Related Solutions

I am trying to make a new code that uses functions to make it. My functions...
I am trying to make a new code that uses functions to make it. My functions are below the code. <?php */ $input; $TenBills = 1000; $FiveBills = 500; $OneBills = 100; $Quarters = 25; $Dimes = 10; $Nickels = 5; $Pennies = 1; $YourChange = 0; $input = readline("Hello, please enter your amount of cents:\n"); if(ctype_digit($input)) { $dollars =(int)($input/100); $cents = $input%100;    $input >= $TenBills; $YourChange = (int)($input/$TenBills); $input -= $TenBills * $YourChange; print "Change for $dollars dollars...
I am trying to integrate a Singleton Pattern into this code I had previously made. Here...
I am trying to integrate a Singleton Pattern into this code I had previously made. Here is my code to a previous project: radius = float(input("Please enter the radius: ")) area = 3.14 * radius**2; print("The area is ", area, "square units.") For this project it must be coded in python. Here are the instructions for the project for reference. Implementing Design Patterns with Python Software Design Patterns may be thought of as blue prints or recipes for implementing common...
Here is the following information on the Cheesecake Factory, I am trying to answer question 1...
Here is the following information on the Cheesecake Factory, I am trying to answer question 1 below. Can you please help me out? Excel assignment. Current Dividend (Source – Yahoo!Finance) $1.28 Required Return (Estimated) 8.9% Current EPS (Source – Yahoo!Finance) $2.14 Current Book Value Per Share (Source – Yahoo!Finance) $13.24 Current EBITDA per share (Source – Yahoo!Finance) $5.25 Current Debt per share è $2.80 Current Cash and Equivalents per share $0.61 Initial Growth Rate for H-Model (Estimated) 9% Terminal Growth...
I am trying to create my own doubly linkedlist class and here is what I have...
I am trying to create my own doubly linkedlist class and here is what I have so far. my addfirst is adding elements forever and ever, and I could use some help. This is in C++. Please help me complete my doubly linkedlist class. the addfirst method is what I would like to complete. #ifndef DLLIST_H #define DLLIST_H #include "node.h" #include using namespace std; template class DLList { private:     Node* head = nullptr;     Node* tail = nullptr;    ...
I have homework on this but I am not sure how to solve it and which...
I have homework on this but I am not sure how to solve it and which formula to use in excel, can u please help me Rebecca is considering buying a 2019 Genesis G70 costing $37,900 and finds that the retaining values of the vehicle over the next four years are as follows: Percent of the total value retained after 24 months: 71% Percent of the total value retained after 48 months: 53% If her interest rate is 5% compounded...
I am trying to implement a search function for a binary search tree. I am trying...
I am trying to implement a search function for a binary search tree. I am trying to get the output to print each element preceding the the target of the search. For example, in the code when I search for 19, the output should be "5-8-9-18-20-19" Please only modify the search function and also please walk me through what I did wrong. I am trying to figure this out. Here is my code: #include<iostream> using namespace std; class node {...
I am trying to do edge detection using matlab. I have posted code here. It does...
I am trying to do edge detection using matlab. I have posted code here. It does not give any error but it's not running it at all. So please help me to fix it and also exaplin each line of this code pls. Thanks! i = imread('C:\Users\Amanda\Desktop"); I = rgb2gray(1i); BW1 = edge(I,'prewitt'); BW2= edge(I,'sobel'); BW3= edge(I,'roberts'); subplot (2,2,1); imshow(I); title('original'); subplot(2,2,2); imshow(BW1); title('Prewitt'); subplot(2,2,3); imshow(BW2); title('Sobel'); subplot(2,2,4); imshow(BW3); title('Roberts');
I am trying to use express to get and post time from a url browser. Here...
I am trying to use express to get and post time from a url browser. Here is my code: var express = require('express'); var app = express(); var url = require('url'); function parsetime (time) { return { hour: time.getHours(), minute: time.getMinutes(), second: time.getSeconds() }; } function unixtime (time) { return { unixtime : time.getTime() }; } app.get('/', function (req, res) { var parsedUrl = url.parse(req.url, true); var time = new Date(parsedUrl.query.iso); var result; if (/^\/api\/parsetime/.test(req.url)) result = parsetime(time); else if...
I am stuck on this problem and I am not sure what the solution is. In...
I am stuck on this problem and I am not sure what the solution is. In C Write item.h and item.c. In item.h, typedef a struct (of type t_item) which contains the following information: t_item: char name[MAX_ITEM_NAME_STRING]; char description[MAX_ITEM_DESCRIPTION_STRING]; Make sure that MAX_ITEM_NAME_STRING and MAX_ITEM_DESCRIPTION_STRING are defined with suitable sizes in your item.h. Typical values are, 25 and 80, respectively. Add the following interface definition to item.h: int item_load_items(t_item items[], int max_items, char *filename); Returns the number of objects loaded...
I am not quite sure how to get this program working or how to start it...
I am not quite sure how to get this program working or how to start it in the first place. Write a full Java program and do the following: 1- Create a generic class and declare a one dim array as a private member. 2- Add a constructor to initialize the array. 3- A set method to set the array. 4- Sort method to sort the array. 5- Print method to print the array. 6- Reverse method to reverse the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT