Question

In: Computer Science

Implement the following function by replacing the pass keyword with your code. Do not change the...

Implement the following function by replacing the pass keyword with your code. Do not change the spelling of the function name or the parameter list.

def order_pie():

Important notes:

  • Ask ONLY these questions, in EXACTLY this order. Do not ask more questions than are necessary to arrive at the right answer.
  • You can expect the input values to be 'yes' or 'no'. For this assignment you do not have to worry about other spellings or capitalization.
  • The return values must be lists and must have the correct number of items. Do not add anything extra.
  • The return values must have every item spelled correctly.
  • The return values must have every item in the order shown.

def order_pie(): pass

# There are only 7 possible sequences of questions.

# The sequence of inputs determines the output.

# Expected results:

# 'yes', 'yes' ---> [ 'apple pie', 'heated', 'strawberry ice cream', 'on the side' ]

# 'yes', 'no' ---> [ 'apple pie', 'heated', 'strawberry ice cream' ]

# 'no', 'yes', 'yes' ---> [ 'apple pie', 'heated', 'vanilla ice cream', 'on the side' ]

# 'no', 'yes', 'no' ---> [ 'apple pie', 'heated', 'vanilla ice cream' ]

# 'no', 'no', 'yes', 'yes' ---> [ 'apple pie', 'heated', 'whipped cream' ]

# 'no', 'no', 'yes', 'no' ---> [ 'apple pie' ]

# 'no', 'no', 'no' ---> [ 'apple pie' ]

Solutions

Expert Solution

def order_pie():
l=list(map(str,input().split()))
if(len(l)==2):
if(l.count('yes')==2):
return ['apple pie', 'heated', 'strawberry ice cream', 'on the side' ]
else:
return [ 'apple pie', 'heated', 'strawberry ice cream' ]
elif(len(l)==3):
if(l.count('yes')==2 and l.count('no')==1):
return [ 'apple pie', 'heated', 'vanilla ice cream', 'on the side' ]
elif(l.count('yes')==1 and l.count('no')==2):
return [ 'apple pie', 'heated', 'vanilla ice cream' ]
elif(l.count('no')==3):
return [ 'apple pie' ]
elif(len(l)==4):
if(l.count('no')==2 and l.count('yes')==2):
return [ 'apple pie', 'heated', 'whipped cream' ]
elif(l.count('no')==3 and l.count('yes')==1):
return [ 'apple pie' ]
print(order_pie())


Related Solutions

Implement a substring search function which searches a string for a given keyword. The function should...
Implement a substring search function which searches a string for a given keyword. The function should return a pointer to the address of the first character of the substring within the original string, if it exists. If the substring is not found within the string, return NULL. If the input is found, print "Key found." otherwise print "Key not found." Your program’s input and output should match what is seen in the example run. • You may only use stdio.h....
Please make my Code working and pass the test but do NOT change anything in main...
Please make my Code working and pass the test but do NOT change anything in main function, thank you. #include <iostream> using namespace std; void sort(int *A, int n){    for(int passes = 0;passes < 2;passes++) { // shift can have only two values either 0 or 16, used for shifting purpose int shift = passes * 16; int N = 1<<(16 + 1);    // Temporary array for storing frequency of upper or lower 16 bits int temp[N];   ...
PLEASE DO NOT CHANGE THE CODE BELOW! In this problem, we will implement an nth root...
PLEASE DO NOT CHANGE THE CODE BELOW! In this problem, we will implement an nth root finder. In particular, please fill in the findNthRoot(int number, int n, int precision) method in the class NthRootFinder. The method should return a string representing the nth root of number, rounded to the nearest precision decimal places. If your answer is exact, you should fill in the answer with decimal places (i.e. with input 41 and precision 5, we should return 41.00000.) You may...
Your code needs to do the following: Create a function called pigLatin that accepts a string...
Your code needs to do the following: Create a function called pigLatin that accepts a string of English words in the parameter sentence and returns a string of those words translated into Pig Latin. English is translated to Pig Latin by taking the first letter of every word, moving it to the end of the word and adding ‘ay’. For example the sentence “The quick brown fox” becomes “hetay uickqay rownbay oxfay”. You may assume the words in the parameter...
This is in Python: Alter your code for previous Do It Now problem, with the change...
This is in Python: Alter your code for previous Do It Now problem, with the change that the row should only be printed by the second number that the user enters. For example, the user enters two numbers of 5 and 7 for the two input lines in the code, and the following will be printed: 5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 =...
implement c++ Quicksort using median of 3 as pivot. this also pass comparator as a function...
implement c++ Quicksort using median of 3 as pivot. this also pass comparator as a function param so it can sort vector in increasing or decreasing order based on the comparator passed. the test code uses std::less comparator. #ifndef QSORT_H #define QSORT_H #include #include using namespace std; template T median_of_three(T& a, T& b, T& c, TComparator comparator) { } template size_t partition(vector& vec, TComparator& comparator, size_t low, size_t high) { // TODO: implement. } template void QuickSort(vector& vec, TComparator comparator,size_t...
1. Implement a method that meets the following requirements: (a) Do not reuse any code for...
1. Implement a method that meets the following requirements: (a) Do not reuse any code for the following: i. Try to write this method with as few lines of code as you can ii. Sorts a group of three integers, x,y and z, into decreasing order (they do not have to be in a sequence). iii. Assume the value in x is less than the value in z. You can also assume there are no duplicates among x, y and...
Implement the following functions in the given code: def babylonian_square_root(N, estimate, precision): This function is provided...
Implement the following functions in the given code: def babylonian_square_root(N, estimate, precision): This function is provided for you to use: def close_enough(x, y, maximum_allowable_difference): My biggest piece of advice to you is to go one line at a time and check your return values after each little change you make. Starter code: # There are different ways of implementing the same idea in math. # Today we will explore a simple way to calculate square roots. # # # #...
Run the following code and answer the following questions: (a) How do accuracy change with changing...
Run the following code and answer the following questions: (a) How do accuracy change with changing the tree maximum depth? [Your answer] (b) What are the ways to reduce overfitting in a decision tree? [Your answer] from sklearn import datasets import numpy as np from sklearn.model_selection import train_test_split from sklearn.tree import plot_tree iris = datasets.load_iris() X = iris.data[:, [2, 3]] y = iris.target X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.3, random_state=1, stratify=y) tree = DecisionTreeClassifier(criterion='entropy', max_depth=10, random_state=1) tree.fit(X_train,...
Assemby language - MIPS Your assembly should implement the C code directly – i.e.,do not ’optimize’...
Assemby language - MIPS Your assembly should implement the C code directly – i.e.,do not ’optimize’ the C code to change the order of operations or reduce computations. Write MIPS assembly code implementing the following C/C++ statement: y = 13 - 11*x; One way of doing the multiply without a multiply instruction is by using many add instructions (x+x+...+x). For this problem you should do it with fewer additions. Hint: We know how to express any integer as a sum...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT