Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*********Python********** 1. Shopping List Write a function called input_shopping_list() that prompts a user for items on their shopping list and keeps prompting the user until

*********Python**********

1. Shopping List

Write a function called input_shopping_list() that prompts a user for items on their shopping list and keeps prompting the user until they enter "Done" (not case-sensitive). It then returns the items in the list.

Your code will then call input_shopping_list() and print the total contents of the shopping list and the total number.

Pseudocode for input_shopping_list():

INITIALIZE empty shopping_list PROMPT the user for an item WHILE item is not "done" ADD item to shopping_list RETURN shopping_list 

(This is just the pseudocode for the function. Your code also needs to call this function.)

Output should look something like this:

Apple Bread Milk Steak Potatoes Total items on shopping list: 5

2. Find common list elements

Write a function find_common_elements(list_p,list_q) that accepts two lists, list_p and list_q, as parameters and returns a new list that contains only the elements that are common between two lists (without duplicates). Make sure your program works on two lists of different sizes. Demonstrate your function works by calling it with 2 different pairs of lists.

Pseudocode for find_common_elements(list_p,list_q):

INITIALIZE empty common_list FOR EACH element e in list_p: IF e is in list_q: ADD e to common_list RETURN common_list

3. Test for an element in a string

Write a function linearSearch(t,v) which accepts a list t and an integer v as parameters. Use a while loop (not a for loop) to iterate through each element of t from beginning to end and, if v is found in t , return its index. If v is not found, return -1. Your code must properly handle lists that contain non-integer elements.

4. Keep track of your pets

Create a dictionary of pet names and what kind of animal they are. For example, if you have a dog named Hammond you will make an entry for "Hammond" : "dog".

1. Put at least three (3) key-value pairs in your dictionary.

2. Write a loop that will print out a sentence for each pair like: "Hammond is a dog."

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genetic Databases

Authors: Martin J. Bishop

1st Edition

0121016250, 978-0121016258

More Books

Students also viewed these Databases questions

Question

=+ Are some laws more important than others? If so, which ones?

Answered: 1 week ago

Question

=+j Describe how EU directives impact IHRM.

Answered: 1 week ago