Exercises
Contents
3.2. Exercises#
3.2.1. Exercise 1#
Write an expression that will find the value of this arithmetic expression:
# write your code here
3.2.2. Exercise 2#
Write an expression that given the following values of x = True
, y = False
and z = False
will find out the value of the following logical expression:
# write your code here
3.2.3. Exercise 3#
Now we will modify the code from the Readings section 3.1.2.3. The user will input a grade and based on the ETH grading table you have to output the corresponding description. Find the details here. If the user inputs a number outside of the specified range then print this statement: Incorrect grade!
.
grade = input('Enter the grade here: ')
# write your code here
---------------------------------------------------------------------------
StdinNotImplementedError Traceback (most recent call last)
Cell In[3], line 1
----> 1 grade = input('Enter the grade here: ')
3 # write your code here
File ~/.cache/pypoetry/virtualenvs/python_for_food_scientists-OgywevK--py3.9/lib/python3.9/site-packages/ipykernel/kernelbase.py:1190, in Kernel.raw_input(self, prompt)
1188 if not self._allow_stdin:
1189 msg = "raw_input was called, but this frontend does not support input requests."
-> 1190 raise StdinNotImplementedError(msg)
1191 return self._input_request(
1192 str(prompt),
1193 self._parent_ident["shell"],
1194 self.get_parent("shell"),
1195 password=False,
1196 )
StdinNotImplementedError: raw_input was called, but this frontend does not support input requests.
3.2.4. Exercise 4#
We have a list of fermented food, but we do not like everything that is there. More precisely, the list contains the following items: milk, yoghurt, beer, cider, tempeh, sauerkraut and kefir. We do not like: milk, cider and kefir. So we need to print everything except of these 3 foods. Write a program to accomplish this using a while loop.
fermented_food = ['milk', 'yoghurt', 'beer', 'cider', 'tempeh', 'sauerkraut', 'kefir']
# write your code here
3.2.5. Exercise 5#
Repeat exercise 4 using a for loop this time but when we encounter sauerkraut
we do not want to continue looping anymore.
# write your code here
3.2.6. Exercise 6 (Optional - Bonus)#
Using a loop structure (either for or while) draw a Christmas tree with a base of 5 stars using asterisks(*). The output should look like this:

# write your code here