Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON CODING HELP What am I doing wrong? Instructions: (Step 1) Find the get_topping_one function. This has already been completed for you. Please read through

PYTHON CODING HELP What am I doing wrong?

Instructions: (Step 1) Find the get_topping_one function. This has already been completed for you. Please read through it, it will give you a hint for what to do for the next functions! To understand this function, we must first introduce slices. This is when we take a range of indices from a string (or list). For example: example = 'ABCDEF' print(example[0]) # prints 'A' print(example[0:2]) # prints 'AB' print(example[3:6]) # prints 'DEF' Topping one can only be 6 letters long, in order for our string slicing to work properly. Since topping one is the beginning of our pizza order we need to extract the topping starting at the first index of the string, which is where we get the 0 in pizza_order[0:7]. The index after the colon is where we want to stop the string. This character at that index will NOT be included in the string slice. Testing Uncomment the two tests given to you for get_topping_one(). The first test should print out cheese and the second one olives.

Get Topping Two (Step 2) This function is very similar to the one you wrote above however it is extracting topping two from the string. You will need to figure out the indexes to extract a 9-letter topping. You wont start at index 0 this time because you dont want topping 1. What index will you need to start at? You need the index where the letter p is at. Then you will have to count and stop at where the comma is at (remember that index is exclusive - meaning it wont be included in the string). Create your own test for this function using this string: cheese, pepperoni, 3000 If you did it correctly, pepperoni should be the only thing returned.

Get price (Step 3) Oh no! The pizza price got turned into cents while being sent to the kitchen! You need to convert the price back to dollars. For the get_price() function, use casting to convert a string value to an int, divide it by 100 and return it. Hint: Here is the general formula for converting from cents to dollars cents/100 = Dollars Note: Dont forget you will need to use string slicing to extract the price from the string! (The price will always be 4 string characters long) Create your own test for this function using this string: cheese, pepperoni, 3000 The value you should see should be 30.

Too Much Cheese! (Step 4) This function returns True or False depending on if there is cheese in the order. Remember cheese can only be topping one because it is 5 letters. You will have to call the get_topping_one function and if that value is equal to cheese, return True. Otherwise, return False. In case you forgot how to call functions inside of functions, here is an example: def appleCount(numApples): # helper function total += numApples return total def findTotalApples(): totalApples = appleCount(numApples) # creating a variable and assigning it to total from the helper function Hint: Pass the pizza_order parameter into get_topping_one when calling the function

Full Order (Step 5) Now we are putting all the steps together. You will need to write a series of if/elif/else statements to meet the following criteria: if too_much_cheese returns True, return Thats a lot of cheese! if too_much_cheese returns False AND get_price returns 45 return Wow thats an expensive pizza! if get_topping_two returns pineapple return Pineapple DOES belong on pizza. elif get_topping_two returns artichoke return Thats an interesting combo. if get_price is less than 12 OR greater than or equal to 50 return Are we sure theyre charging us right? else return Now thats a smokin deal! Give me more! Hint: You will need to call the other functions you completed in prior steps Hint: Pay close attention to the wording given to determine if you need if, elif, or else

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

\( \begin{aligned} 1 & \text { \#\# } \\ 2 & \text { \#\# Lab } 05 \text { - Pizza Order } \\ 3 & \text { \#\# } \\ 4 & \\ 5 & \text { \# STEP } 1 \\ 6 & \text { def get_topping_one(pizza_order): } \\ 7 & \text { return pizza_order[0:6] } \\ 8 & \\ 9 & \\ 10 & \text { \# STEP 2 } \\ 11 & \text { def get_topping_two(pizza_order): } \\ 12 & \text { start = pizza_order.find("p") } \\ 13 & \text { end = pizza_order.find(",", start) } \\ 14 & \text { return pizza_order[start:end] } \\ 15 & \\ 16 & \text { STEP 3 } \\ 17 & \text { STEP }\end{aligned} \) \begin{tabular}{l|l} 33 & \# STEP 5 \\ 35 & def full_order_pizza_order): \\ 36 & if (too_much_cheese(pizza_order)==True): \\ 37 & return "That's a lot of cheese!" \\ 38 & if((too_much_cheese(pizza_order)==False) and (get_price(pizza_order)==45)): \\ 39 & return "Wow that's an expensive pizza!" \\ 40 & if (get_topping_two (pizza_order)=="pineapple"): \\ 41 & return "Pineapple DOES belong on pizza." \\ 42 & elif (get_topping_two (pizza_order)=="artichoke"): \\ 43 & return "That's an interesting combo." \\ 44 & if (get_price(pizza_order)>=50): \\ 45 & return "Are we sure they're charging us right?" \\ 46 & else: \\ 47 & return "Now that's a smokin' deal! Give me more!" \\ 48 & \\ 49 & \end{tabular} ke, 1700') incorrectly returned Now that's a smokin' deal! Give me more

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 Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

5. Understand how cultural values influence conflict behavior.

Answered: 1 week ago

Question

e. What do you know about your ethnic background?

Answered: 1 week ago