Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a python code In practical 1 you wrote an algorithm for calculating a coffee brew ratio based on dose and yield, something like: get

write a python code
image text in transcribed
image text in transcribed
In practical 1 you wrote an algorithm for calculating a coffee brew ratio based on dose and yield, something like: get dose, yield ratio = yield / dose print ratio Here, "ratio" is the number of grams of yield (brewed coffee) per 1 gram of dose (ground coffee), expressed as a float, 6.9.2.5 According to La Marzocco: Using traditional Italian espresso nomenclature, we'll refer to a brew ratio of 1:1 (18 grams in / 18 grams out, for example) to 1:2 (18 grams in / 36 grams out) as a "ristretto" espresso; a 1:2 to a 1:3 ratio as a "normale" espresso; and a 1:3 to 1:4 ratio as a lungo espresso Write an algorithm to determine the coffee "style" based on the brew ratio. E.g. a ratio of 2.5 (1:2,5) would be a "normale". Note: We will consider anything outside the ranges defined above to match the nearest style, E.g. 1:0.1 wouldn't be good coffee, but we'd call it a "ristretto" and 1:100 would be dishwater, but let's call it a "lungo". Now, that looks like the sort of thing we could use a function for in our code, doesn't it? We pass in a number like 2.5 and the function returns a string like "normale". This is a very common style of function, converting one value to another. Write a second algorithm (it will be very similar, so copy-and-paste then modity) for a function that takes in ratio and returns the style. Use the above examples as a reference. This is very much like the function for determining a weight category based on a BMI value. Now write this function in Python. Think of a good verb-phrase name. Next, like we did with the example, let's write another function to test it: Next, like we did with the example, let's write another function to test it: def test_coffee(): style = determine_coffee_style(1) print (style) This should be ristretto style = determine_coffee_style(2) print(style) # This should be normale style = determine_coffee_style(13.5) print(style) # This should be lungo Notice that we tested at least one of each style and some boundary conditions. (You could do more complete testing if you want.) Now write a main program that asks the user for the dose and yield, works out the brew ratio then uses your function to determine coffee style. Remember that main() should always be your first function in any program file. Note: yield is a Python statement (keyword) so you can't use it as a variable. As a rule, never use Python builtin words as variables, even if you're allowed to (eg, sun and print are Python functions that it's possible to use as variable names... but don't!) Sample: Dose: 18 Yield: 36 1:2.8 is considered normale

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

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions

Question

=+multiplicity 1). If A + 1, then |A| Answered: 1 week ago

Answered: 1 week ago