85 lines
2.4 KiB
Plaintext
85 lines
2.4 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# IOU\n",
|
|
"\n",
|
|
"![IOU](IOU.png)\n",
|
|
"\n",
|
|
"Mark, Anna and Dennis had a great weekend in Hamburg and decided to split the cost equally. Consider that Mark spent 25 EUR, Anna 45 EUR and Dennis 17 EUR. Compute how much each owes the other two\n",
|
|
"\n",
|
|
"Use the cell below to calculate how much each owes the other two, and how much each should get from the other two.\n",
|
|
"\n",
|
|
"Make sure the code is easily adaptable to cases where Mark, Anna and Dennis have spend different ammounts.\n",
|
|
"\n",
|
|
"Hints:\n",
|
|
"\n",
|
|
" * Calculate how many each should pay, regarless of how much they already paid, you could call this variable `average`.\n",
|
|
" * To find out how much someone still owes, you can use `average - paid`, which might be negative. On the other hand, `paid - average` expresses how much someone should get.\n",
|
|
" * `max( ..., ... )` returns the maximum value out of two (or more), think how `max(0, ...)` can be used to clip negative values to `0`."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"mark = 25\n",
|
|
"anna = 45\n",
|
|
"dennis = 17\n",
|
|
"\n",
|
|
"# YOUR CODE\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"# END OF YOUR CODE\n",
|
|
"\n",
|
|
"print('name owes gets')\n",
|
|
"print('Mark {: 6.2f} EUR {: 6.2f} EUR'.format(mark_owes, mark_gets))\n",
|
|
"print('Anna {: 6.2f} EUR {: 6.2f} EUR'.format(anna_owes, anna_gets))\n",
|
|
"print('Dennis {: 6.2f} EUR {: 6.2f} EUR'.format(dennis_owes, dennis_gets))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"**Expected output**\n",
|
|
" 1. `name owes gets`\n",
|
|
" 1. `Mark 0.00 EUR 3.67 EUR`\n",
|
|
" 1. `Anna 12.67 EUR 0.00 EUR`\n",
|
|
" 1. `Anna 0.00 EUR 16.33 EUR`"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"hide_input": false,
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.4.3"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|