-1

I got some assignments that were written in jupyter notebook where the code is written as json text and with marksdown, my problem however is that some of the text is very readable so l am able to read the text to the assignements while the code starting from { to } seems unreadable. Therefore l am wondering if the code containing cells, id, metadata etc is supposed to readable or if it is just a matter of formatting?

I have tried different solutions such as opening the file in jupyter notebook, seperating the code and etc in jupyter notebook so that the code and markdowns are seperated. I have tried to Google around and find some solutions but was unable to find any. The file type is ipynb (Jupyter Source File).

To try to clearify my question. I am supposed to be able to convert the code and the markdowns into one file? I am able to copy and paste the markdown text since it is plain text but can not really figure out what to do with the actually code in the text. Grateful if anybody has some tips on how to solve this. Also to clearify, l do not need help to solve the actually assignement in the text, just being able to read to text.

{
"cells": [
{
"cell_type": "markdown",
"id": "13935fcb",
"metadata": {},
"source": [
"# Exercise 1"
]
},
{
"cell_type": "markdown",
"id": "b3f0b8fb",
"metadata": {},
"source": [
"# Task 1: Population Growth\n",
"----\n",
"\n",
"Build upon the example from the lecture about population growth in Iceland and write the following program:\n",
"\n",
"* The program prompts the user for:\n",
" - Name of the area (e.g., Iceland, Finnmark, etc.)\n",
" - Growth rate\n",
" - Start year\n",
" - End year\n",
" - Population at the start year\n",
"* The program calculates the population size at the end year\n",
"* The program summarizes and provides feedback about the provided values\n",
"* The program displays the population at the end year\n",
"* The program indicates how much the population has grown in absolute numbers and relative to the initial population (in percentage)\n",
"\n",
"Population growth is assumed to be described by the logistic equation as follows:\n",
"\n",
"
\n
"
,
"
(
)
=
1
+
−
\n
"
,
"
\n","P(t)=
fracK1+Ae 
−rt
 \n","\n",
"Where:\n",
"* $P(t)$: Population at time $t$\n",
"* $t$ is the time\n",
"* $r$ is the relative growth rate, e.g., 2%\n",
"* $K$ is the carrying capacity of the population\n",
"* $e$ is Euler's number: $e\approx 2.71828$\n",
"\n",
"$A$ is a coefficient defined as:\n",
"
\n
"
,
"
=
−
0
0
\n
"
,
"
\n","A=
fracK−P 
0
​
 P 
0
​
 \n","\n",
"Where $P_0$ is the population at $t=0$"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "5a2b55e4",
"metadata": {},
"outputs": [],
"source": [
"\n",
"# Your code here :)\n"
]
},
{
"cell_type": "markdown",
"id": "57d2e25e",
"metadata": {},
"source": [
"# Task 2: Savings Calculator\n",
"----\n",
"\n",
"If we save a fixed amount $P$ that we deposit into an account $n$ times per year, with an annual interest rate of $r$ percent, and we save for $t$ years, the final amount in the savings account is given by:\n",
"
\n
"
,
"
=
(
(
1
+

)
\n
"
,
"
\n","F=P
cdot
left(
fracleft(1+fracrnright) 
nt
 −1fracrn
right)\n","\n",
"\n",
"Create a program that asks the user to input the deposit amount, interest rate, number of deposits/interest adjustments per year, and the number of years. The program should provide the following feedback:\n",
"* The program summarizes and provides feedback on the numbers entered by the user\n",
"* The program calculates and displays the final amount in the savings account\n",
"* The program indicates how much of the final amount is interest and deposits, both in percentage and amount\n",
"\n",
"(Note that $r$ in the formula is not in percentage; for example, 2% = 0.02)\n",
"\n",
"### If You Want\n",
"----\n",
"If you'd like, you can also incorporate inflation, wealth tax (approximately 1%), and a tax rate (22% of interest income) into the calculations."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "6bab3d75",
"metadata": {},
"outputs": [],
"source": [
"\n",
"# Your code here :)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
  • 1
    This is a Jupyter notebook, and opening in Jupyter should display it as intended. Can you please clarify what you are asking? The sole question "I am supposed to be able to convert the code and the markdowns into one file?" seems rather like a statement, and we cannot tell you what you are supposed to do to begin with. Are you asking how to *execute* the code? – MisterMiyagi Aug 24 '23 at 17:00
  • 1
    You may want to check out `nbformat` for doing this progammatically. It reads in `.ipynb` files and lets you program it to separate out the code or markdown. It has the concepts for cells and cell types backed right in. Check out more explanation and links [here](https://stackoverflow.com/a/74379308/8508004). – Wayne Aug 24 '23 at 18:08
  • Hi @Wayne and MisterMiyagi, thanks so much for your helpfull answers. After som trying back and fourth l was able to open the Jupyter notebook without having the "raw code". – Sebastian Aug 24 '23 at 19:05
  • As MisterMiyagi was getting at, it appears you just weren't realizing currentJupyter `.ipynb` files are json text. I'll add though for anyone coming here because of your title later that you can convert them to pure text (markdown-formatting) on the command line with [jupytext if you were really curious](https://jupytext.readthedocs.io/en/latest/using-cli.html#command-line-conversion). And for viewing a `.ipynb` file you have those options [here](https://stackoverflow.com/a/71094775/8508004) if you don't want to install Jupyter on your machine. Or if the `.ipynb` file is online, you can ... – Wayne Aug 24 '23 at 19:30
  • use `nbviewer` to examine the 'static' representation of the notebook file, see [here](https://stackoverflow.com/a/73991815/8508004) for more about that. I put 'static' in quotes because some javascript-based interactive components will work inside nbviewer-renderings, such as plotly plots, and so 'static' can be misleading. – Wayne Aug 24 '23 at 19:32
  • In one of those links, I mention JupyterLite. However, since that was added there as an 'update' it may not be as obvious and so I'll highlight it here. **[JupyterLite](https://jupyterlite.readthedocs.io/en/latest/), powered by Web Asesmbly (WASM) and running inside your local browser is definitely an easy option if you are just looking to view the notebook `.ipynb` file**, or at least most of it since it may have trouble with fancy widgets & offerings that need pure active Python. Importantly, no content ever leaves your machine when you use JupyterLite. – Wayne Aug 24 '23 at 20:00

0 Answers0