Professional Documents
Culture Documents
Sequences
BANA3020 Introduction to Programming with Python Fall 2023 – Week 07
(a) No submission by the deadline will incur 0.25 point deduction for each problem (most of the
problems are due at the end of the lab session).
(b) The instructor will deduct an additional 0.25 point per problem for each day past the deadline.
(c) The penalty will be deducted until the maximum possible score for the lab practice reaches zero
(0%) unless otherwise specified by the instructor.
Problem 2
You’re going shopping for a friend, and you need to buy 3 items. First, create an empty list for your shopping
cart called my_cart = []. Then:
Unfortunately your friend is lactose intolerant! That means your friend DO NOT want you to buy ANY of
the following items:
dairy_products = ["cheese", "milk", "cream", "butter", "chocolate", "yogurt"]
• Remove any items in dairy_products from my_cart (recall the in keyword from lecture). It should
be a list of strings without any dairy products.
Hint: There are multiple ways to solve this problem. You can check for each input and only add to cart if
the input is not in dairy_products, or you can add everything to the list, and remove the dairy products
afterward.
• Print my_cart as a comma-separated string (use join). If there aren’t any non-dairy item, print an
empty string.
Problem 3
Write a Python program that prompts the user to input a list of names separated by commas. Your task is to
extract and display the first, middle, and last names in the list.
Utilize list methods and indexing to achieve this without using loops. Note: To find the middle element in
a list, use length//2 for both odd and even lists. This convention helps in accessing the center element
without loops.