Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in python What can and can't I use or do? Many built-in functions in python would make our tasks so trivial that you wouldn't really

in python image text in transcribed
image text in transcribed
image text in transcribed
What can and can't I use or do? Many built-in functions in python would make our tasks so trivial that you wouldn't really be learning, just "phoning it in". The following restrictions are in place for the entire project, and individual functions may list further restrictions (or pointed reminders). The whole point of this assignment is to practice writing loops, and seeing lists in the most basic way possible. There are indeed many different approaches that can "hide the loop" inside a function call, conversion to a different type, and other ways, but we want to make sure you're getting the practice intended from this assignment. Learning to code has different goals than finishing programs. Restrictions: you can't import anything you can't use recursion, recursion will be used in future assignments none of these functions need to call any of the other functions you've created no built-in functions other than those in the "allowed" list. no usage of sets, dictionaries, file 1/0, list comprehensions, or self-made classes. Just focus on lists/loops. Allowed: variables, assignments, selection statements (if-elif-else), loops (of course!), indexing/slicing. I basic operators: +, - 1.17.%, --, !=, , =, in, not in, and, or not. when you need to build up a list, you can start with the empty list [] and .append() values into it. only these built-in functions/methods can be used: abs(), len(), range(). str(), int(), .append(), .extend() .pop() . . . . Hints In my solution, I used the following things: basic operators, assignment, branching/loops, indexing, built-ins functions abs(). len(), range(). when the answer is a list, I build it up from an initial [] by calling .append() repeatedly. I used .pop() in one function. "Bubble sort" for sorting. you'll need to use at least one loop per function, if not more! def marble_cakes (Flavor, flavor_cakes): Given an item flavor, and a list flavor_cakes return how many marble cakes can be included in the "marble cakes menu". Assume a marble cake is two different flavors. The list flavor_cakes contains different flavors but could also contain flavor. o Assume: flavor is a string, flavor_cakes is a list of strings. o Reminder: you must not hard-code the flavor_cakes items; use the given list argument! marble_cakes ("chocolate", ["vanilla", "almond"1) + 3 # chva, da, vel marble_cakes ("chocolate", ("chocolate"]) - # Possible combination chadh, marble_cakes("chocolate", ("carrot", "chocolate"])+1 #da 2 O def get_cakewithtopping(cake, toppings): Given an item cake, and a list of toppings, create and return a list of possible combinations, using for the combination name. Preserve ordering. Assume: cake is a string, and topings is a list of strings. The list might be empty. get_cakewithtopping("carrot", ["MM", "oreo"]) -["carrot-MM", "carrot-oreo"] get_cakewithtopping ("pistachio". ("sprinkles"]) ["pistachio-sprinkles"] get_cakewithtopping("velvet", (1) ] def sales_sort(cakes, sales): Given a list of strings cakes, a corresponding list of ints sales, return a list of the cakes sorted from highest to lowest number of sales. Preserve the original order in case of tie, Assume: cakes is a list of strings, sales is a list of positive ints. cakes and sales are the same length (which may be zero). Restrictions: remember, you can't call any built-in sorting functions. sales sort(["pistachio","velvet"],[8,7]) - ("pistachio", "velvet") sales_sort(1,0) - ) sales sort(["lemon", "carrot", "dark"],[2,50,50])-("carrot", "dark", "lemon") def dif_sales(cakes, sales): Given a list cakes, and a corresponding list sales, return a list of cakes which sales differ from other cakes (i.e. its sale appears only once in sales). Preserve ordering. o Assume: cakes is a list of strings, and sales is a list of ints. Both lists are same length (which may be zero). dif_sales(["carrot", "velvet", "lemon"), (1,5,1]) = ["velvet"] dif_sales(["chocolate", "vanilla"], [9,1]) - ["chocolate", "vanilla"] dif_sales({ "velvet", "white", "dark", "banana"), (2,5,5,2]) + []

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

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions