<jupyter_start><jupyter_text>Jupyter and Python example  [Download exercises zip](../_static/generated/jup-and-py-example.zip)[Browse files online](https://github.com/DavidLeoni/jupman/tree/master/jup-and-py-example)Most complex example of a notebook with exercises both in Jupyter and Python files, and 'advanced' features What to do- unzip exercises in a folder, you should get something like this: ```jup-and-py-example   jup-and-py-example.ipynb   jup-and-py-example_sol.ipynb      lab.py         lab_test.py    lab_sol.py```- open the editor of your choice (for example Visual Studio Code, Spyder or PyCharme), and edit `lab.py` file- Go on reading this notebook, and follow instuctions inside.  Let's beginYou are going to program a simulator of bouncing clowns. To do so, we are going to load this module:<jupyter_code>import local
local.gimme(5)<jupyter_output>It was a 5 indeed<jupyter_text>**Download test data**Local file: * [example.txt](example.txt)* [example.csv](example.csv)  Global image![cc-by-5754](../_static/img/cc-by.png)  Local exercise image![leaves-98231](img/leaves.png)  Python tutor<jupyter_code>x = 5
y = 6
z = x + y

jupman.pytut()<jupyter_output><empty_output><jupyter_text>Exercise in JupyterImplement this function:<jupyter_code>def hello(s):
    #jupman-raise
    return ['hello',s]*1000
    #/jupman-raise
    
hello_db = hello("Guybrush")
#jupman-purge
# note purged stuff is not considered a solution
jupman.save_py('expected_hello_db.py', hello_db)    
#/jupman-purge
hello_db[:10]<jupyter_output><empty_output><jupyter_text>Full expected output is in file `expected_output_db.py`, if you can't manage to solve the exercise, as a last resort you can type: `from expected_hello_db import *`(DO NOT copy-paste file content, it would probably mess Jupyter up)<jupyter_code>from expected_hello_db import *
expected_hello_db[:10]<jupyter_output><empty_output><jupyter_text>Other example:<jupyter_code>hello_db2 = hello("Threepwood")
#jupman-purge
# note since this is purging, we can import any lib we want, 
# they don't need to be present in user system
import sys
sys.path.append('../')
import jupman
jupman.save_py('expected_hello_db2.py', hello_db2)    
#/jupman-purge
hello_db2[:10]<jupyter_output><empty_output><jupyter_text>Exercise using previous outputWrite some code which says hello 3 times using previous functionand<jupyter_code>print(hello('Guybrush')[:6])<jupyter_output>['hello', 'Guybrush', 'hello', 'Guybrush', 'hello', 'Guybrush']<jupyter_text>Question in Jupyter**QUESTION**: Why learn coding? **ANSWER**: So they pay me more```pythonx + 1```Some other comment    Some nasty formatting> even more formatting  Exercise in PythonStart editing `lab.py` in text editor<jupyter_code>from lab_sol import *<jupyter_output><empty_output><jupyter_text>addImplement `add` function:<jupyter_code>add(3,5)<jupyter_output><empty_output><jupyter_text>subImplement sub function<jupyter_code>sub(7,4)<jupyter_output><empty_output><jupyter_text>Fine grained purging<jupyter_code>#jupman-purge-input

print("This cell input will be completely removed")
#jupman-purge-output

print("This cell output will be completely removed")
#jupman-purge-io

print("This cell input and output will be completely removed")
import lab_test
jupman.run(lab_test.MyTest)<jupyter_output>..
----------------------------------------------------------------------
Ran 2 tests in 0.001s

OK
{'fraction_non_alphanumeric': 0.13047311196003528, 'fraction_numerical': 0.011460476050543638, 'mean_word_length': 5.3626168224299064, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 39, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '265511', 'license': 'Apache-2.0', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1143, 'n_words': 302, 'path': 'jup-and-py-example/jup-and-py-example-sol.ipynb', 'repo_name': 'DavidLeoni/jubuild', 'size': '3403'}