<jupyter_start><jupyter_text>PyCamp:  Next Level Camp MightyMoose![bonfire](./PyCampEventListening/camping.png)  Camp Description (March - April 2020):This camp will show our students just how powerful Python can be! Campers will explore its terminal basics and learn how to find and understand Python packages to make any project they can imagine! Advanced topics will include AI (Artificial Intelligence), Database Operations, and more. Welcome to the real world of programming! Prerequisites:Previous Python experience or other text-based programing language (JavaScript, C, etc.)  FAQ**Q**  What does FAQ mean?**A**  FAQ means Frequently Asked Questions**Q**: What IDE should I use?**A**: Try out a bunch!  The instructor will show you several.  Try Spyder, it comes with [Anaconda](https://www.anaconda.com/downloads).**Q**: What version of Python will we need?**A**: Python3 or later (not 2.7). I recommend getting Python from [Anaconda](https://www.anaconda.com/downloads) as we're going to be using Jupyter Notebooks and JupyterLab and these are included in that distro.**Q**: What if I'm home from school and want to learn calculus?**A**: Here's [a starting place](https://github.com/4dsolutions/School_of_Tomorrow/blob/master/stats_works.ipynb) (one of many).  Or lets just [plot some functions](PlotFunctions.ipynb).**Q**: Do I need Git?**A**: You will have a better experience if you can clone [this repo](https://github.com/4dsolutions/python_camp).  Then you can ```git pull``` future updates.  On Windows?  [Get git](https://gitforwindows.org/) here.**Q**: Who's a good Git teacher on Youtube?**A**: <NAME> is an excellent teacher on many subjects. Checkout his [Github for Poets playlist](https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZF9C0YMKuns9sLDzK6zoiV).**Q**: Who's a good Python teacher on Youtube?**A**: The Socratica channel has [many pithy Python videos](https://www.youtube.com/playlist?list=PLi01XoE8jYohWFPpC17Z-wWhPOSuh8Er-). Make your own?**Q**: Where's a good place to begin with data science?**A**: Follow [<NAME>](http://vanderplas.com/) and study his work.**Q**: I already have an older version of Python3 that's not Anaconda, will that be OK?**A**: In a BYOD camp we leave those decisions up to you.  You may be concerned that too many Pythons will leave you with [a tangle](https://xkcd.com/1987/).**Q**: I've already done some Object Oriented Programming (OOP), am I too advanced for this course?**A**: Do you know [how Python does OO](animals.py)?  Coding up ```animals.py``` is one of the many hikes.  We won't do them all.  Your instructor will get a sense of what hikes might work best, given who shows up in your group.  DAY ONEPython is used for many purposes in many walks of life.We're going to tell stories around the campfire (share lore) and take hikes (work out, go places, see things, try stuff out).See **More Campfire Stories** at the end. Example Workout (hike):* Create your Github account (if you don't already have one)* Fork this repo* Clone the forked repo (your copy) and change at will* Clone [this repo](https://github.com/4dsolutions/python_camp) (original) and ```git pull``` for future updates* Bookmark the [Git docs](https://git-scm.com/doc)* Download the Anaconda distro of Python[Looking for games](https://pypi.org/project/freegames/)?How about [Pygame](https://pygame.readthedocs.io/en/latest/)?  Repl.it lets you try it out. Hike:Run, Fork, Port, Modify any / all of the following:* [PyCamp Screen Saver](https://repl.it/@kurner/PyCamp-Screen-Saver)* [PyCampEventListening](https://repl.it/@kurner/PyCampEventListening)* [FishyDemo2](https://repl.it/@kurner/FishyDemo2)If you get serious about Pygame, install it locally (e.g. through [PyCharm](https://www.jetbrains.com/pycharm/)).  Examples of Python in Action* [Arbitrary Precision Computing](https://github.com/4dsolutions/Python5/blob/master/Extended%20Precision.ipynb) (e.g. "pi to a thousand places")* [A Library](https://github.com/4dsolutions/School_of_Tomorrow/blob/master/Flextegrity_Lattice.ipynb) for working with [POV-Ray](http://povray.org)* [A Flask website](http://thekirbster.pythonanywhere.com/)<jupyter_code># Arbitrary Precision Demo

# lets see if your calculator can keep up with Python

import decimal

with decimal.localcontext() as ctx:  # context manager
    ctx.prec = 1000
    n = decimal.Decimal(1e102)
    e = (1 + 1/n) ** n  # euler's number as n->infinity
    print("{}".format(str(e)[:200]))<jupyter_output>2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427426107251017773537272944324338265727075159043553471000244537649931411462661698975357333166908648006<jupyter_text>Everyday mathematics comes alive in Python's Jupyter Notebooks<jupyter_code>from primes import *
isprime(11133995233)
factors(2883704765347)
print(eratosthenes(1000))<jupyter_output>Eliminating multiples of: 2
Eliminating multiples of: 3
Eliminating multiples of: 5
Eliminating multiples of: 7
Eliminating multiples of: 11
Eliminating multiples of: 13
Eliminating multiples of: 17
Eliminating multiples of: 19
Eliminating multiples of: 23
Eliminating multiples of: 29
Eliminating multiples of: 31
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823[...]<jupyter_text>For further reading:* [The Calculator of Tomorrow:  Using Arbitrary Precision](https://medium.com/@kirbyurner/calculator-of-tomorrow-using-arbitrary-precision-8f219b0092d9)  DAY TWOSome of our skill building topics:* downloading and installing [packages](https://pypi.org/) with conda and [pip](https://pypi.org/project/freegames/)* importing modules and packages (understanding about ```__init__```)* Python and [Unicode](https://codepoints.net/) (printing ranges of unicode characters)* sys.argv and passing arguments from the command line* many number types in Python (including [3rd party](https://gmpy2.readthedocs.io/en/latest/))<jupyter_code># calling python through the operating system
! python -m unicode_fun
! python -m unicode_fun arabic
! python -m unicode_fun emoji
import animals
animals.test_dog()<jupyter_output>Eating a meal of 1 things
doggie doesn't feel well.
🍜<jupyter_text>DAY THREE Machine LearningOur toolkit: [scikit-learn](https://scikit-learn.org/stable/index.html)Lets use a fine specimen of [an on-line tutorial](https://www.codementor.io/@garethdwyer/introduction-to-machine-learning-with-python-s-scikit-learn-czha398p1), forked to add requirements.txt so we can run it in binder.Stories about ML / [DL](https://playground.tensorflow.org/) (overview of AI) Hike:* Warm up on [Repl.it](https://repl.it/@kurner/machine-learning-intro) (sentiment analysis) -- you can cut and paste this to your local IDE.* Dive in to [sklearn-intro](https://github.com/4dsolutions/sklearn-intro) (headline or clickbait?) -- you might want to clone this one. Hike:* [Hand-written Digit Recognition](https://scikit-learn.org/stable/auto_examples/classification/plot_digits_classification.html) (runs in binder, see launch bar) Data Sources:*  [Kaggle](https://www.kaggle.com/datasets)*  [UCI](http://archive.ics.uci.edu/ml/index.php)  DAY FOUR Database OperationsStories about Data ScienceTopics:* [context managers](ContextManager.ipynb) in Python (a type of class used with keyword "with")* connection versus cursor objects* [SQL](https://sqlite.org/index.html) (via sqlite3)* pandas DataFrame Hike:* Clone or Unzip a Github Repo* Skill build around SQL* Skill build around Jupyter Notebooks and Jupyter Lab<jupyter_code>from connector import DB
with DB("./data/x_files.db") as db:
    print(db.conn)
    print(db.curs)
query = "SELECT * FROM ufo_sightings WHERE city = 'Toledo' AND state = 'OH'"

with DB("./data/x_files.db") as db:
    obj = db.curs.execute(query)  # use the cursor object to
    print("SHAPE           DATE/TIME")
    for rec in obj.fetchall():    # result set 
        if not rec[3]: # filter out if no shape
            continue
        print("{:15} {:16}".format(rec[3], rec[5]))
import usercrud  # CRUD: create, retrieve, update, delete
import hashlib
usercrud.add_one("Charlie", "spam")
# pw = input("Please enter your password. > ")
pw = "<PASSWORD>"
hashpw = hashlib.sha256(bytes(pw, encoding='utf-8')).hexdigest()
print(hashpw)
# you might need a cell like this to force recompilation of a module
# import imp
# imp.reload(usercrud)
def table():
    print("Users Table")
    for record in usercrud.fetch_all():
        print("{:10} {:256}".format(*record))
table()
import pandas as pd
import sqlite3 as sql
con = sql.connect("./data/x_files.db")
data=pd.read_sql_query("SELECT  count(*) as how_many, shape "
                       "FROM ufo_sightings GROUP BY shape ORDER BY how_many", con)
data.head(10)<jupyter_output><empty_output><jupyter_text>For Further Reading:[Polyhedrons in a Database](https://github.com/4dsolutions/Python5/blob/master/Polyhedrons%20101.ipynb)  DAY FIVE Pulling It All TogetherLets build a web server and run it on localhost!Stories:Python and Websites (some of the solutions)Visualization Libraries:* [matplotlib](https://matplotlib.org/)* [Bokeh](https://twitter.com/bokeh)* [Altair](https://altair-viz.github.io/)[Example Website](http://thekirbster.pythonanywhere.com)Topics:* HTTP* JSON, CSV, XML Hike:* conda install flask* conda install requests* run and modify the web application(s)<jupyter_code>import requests
myrequest = requests.get("http://thekirbster.pythonanywhere.com/api/elements?elem=H")
myrequest.text<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1261136408631954, 'fraction_numerical': 0.07285686002771728, 'mean_word_length': 5.145377128953771, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 35, 'lorem ipsum': 0, 'www.': 7, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 23, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '316545', 'license': 'MIT', 'n_tokens_mistral': 3956, 'n_tokens_neox': 3259, 'n_words': 1097, 'path': 'PyCampNextLevel.ipynb', 'repo_name': 'westurner/python_camp', 'size': '10121'}