# 02-Tooling#

## Announcements#

• CL1 due 11:59PM Wednesday 28 September 2022

• Coding labs run Wednesday in CSB 115

• Please go to the section you’re assigned if it works

• If you need to go to another section that’s fine

## Q&A#

• I was on the zoom lecture so I was wondering if they will still be happening? Or if it’s mainly in person/podcasted format now.
I had a technical issue. Hopefully it’s fixed now and we will have a proper hybrid class

• I am curious about the final project. I wonder if I will be able to actually create something at the end of the class! I have a bunch of ideas and cool concepts that are possible but, I do not know if it is possible for me to complete. I look forward to discovering if I can make a cool app!_
More project info covered in this lecture. Also you can check out the new course website

• Are iClicker questions mandatory?
No! They are there to give you a way to interact and keep awake

• The most confusing part of this lecture for me are asterisks. I am not really sure when to use them since you can use underscore instead.
I’m sorry to break the news, but lots of times in programming there are multiple ways to do exactly the same thing. Like in markdown you can use _ or * as you prefer to make italics. Or like x=”blah blah” is the same as x=’blah blah’ in Python. You will see a lot of this :)

• How can we jump out of Datahub and have our own copy of the codes.
You can download files from Datahub to your own computer! File tab -> click the tickbox on left side of the filename -> click Download button at top of files list

• How does Anaconda fit into what we learned about Jupyter notebooks?
Anaconda is an all in one download of a bunch of tools (e.g. Python, Jupyter, various packages) that will pretty much replicate what Datahub has on your own computer

• Are coding labs meant to be completed during the scheduled lab time? Or is that time set for us to ask questions about lab?
Yes to both! The TA will go through some things and then open it up for questions. In the meantime you can work on your own.

## Tools#

• Python

• datahub

• Jupyter Notebooks

• Anaconda

This notebook will guide through the tools you will need for class materials and assignments, and how to get them.

### Clicker Question #1#

How excited are you for COGS 18?

• A. Super excited!

• B. The most excited!

• C. Couldn’t be more excited!

• D. I love 8AM classes!

### Prerequisites#

This course and associated materials do not presume any prior knowledge of Python, or programming in general.

To work with the course materials, you will need make sure you have access to the tools tools described here on datahub.

It will be helpful for the final project if they are also installed on the computer you will be using.

None of the materials are computationally heavy.

### What do you need?#

• Python (datahub uses python v3.9)

• Jupyter Notebooks

Python is a programming language, whose development is led by the Python Software Foundation (PSF).
The official Python organization website is available here.

## Python#

• Versions: there are different versions of Python.

• We will be using 3.9 on datahub (>3.6 required)

• Packages: Python includes a “base set” of code (the standard library), and an extensive ecosystem of third party packages

• In this course, we will largely focus on the standard library

• For access to other packages when we need them, we will use Anaconda

Jupyter notebooks are a way to intermix code, outputs and plain text. They run in a web browser, and connect to a kernel to be able to execute code.
The official Jupyter website is available here.

## JupyterHub#

JupyterHub allows Jupyter notebooks to be shared across multiple users.
The official JupyterHub website is available here.

### Datahub#

UCSD hosts its version of JupyterHub and calls it datahub. This is what you’ll be using in class.

It is available here: http://datahub.ucsd.edu

### When to use Datahub?#

• Course Lecture Slides

• CodingLabs

• Assignments

• Final Project/Exam

#### Lecture Slides:#

Once you’ve logged into datahub, click on the the following link: https://datahub.ucsd.edu/hub/user-redirect/git-pull?repo=https://github.com/COGS18/LectureNotes-COGS18&urlpath=tree/LectureNotes-COGS18/&branch=main

#### CodingLabs & Assignments:#

• Fetch & complete on datahub

• do not change file names

• do not copy cells provided

• print() statements encouraged

• For Submission:

• Before you click submit, make sure it’s the thing you want to submit

• You must click submit.

• Always check that the CodingLab/Assignment/Exam shows up under “submitted assignments”

• You can submit as many times as you want

## Jupyter Notebooks#

• Markdown

• code cells

Jupyter notebooks are a way to combine executable code, code outputs, and text into one connected file.
The official documentation from project Jupyter is available here and they also have some example notebooks here .
For more useful information, check out Jupyter Notebooks tips & tricks , and more information on how notebooks work.

### Cells#

The main organizational structure of the notebook are cells.

Cells are an independent ‘unit’. When you click into a cell, you can ‘run’ it by clicking Shift + Enter, or by pressing the play (Run) button above.

Cells come in different types for writing different things - mainly, text or code.

#### Markdown Cells#

Cells, can be markdown (text), like this one.

A brief note about Markdown. It’s a way to specify all formatting within the text itself.

For example, italicized text can be specified with an underscore or single asterisks.

Bold text requires two underccores or two asterisks.

#### Clicker Question #2#

What does three underscores around text accomplish?

• A) bold

• B) italicize

• C) bold + italicize

• D) normal text

• E) I’m lost

you can write/edit your markdown text here to determine the answer to the question

## Headers are specified with a pound sign#

### The more pound signs, the smaller the header#

#### But it’s still larger#

than just plain text.

Lists are also possible:

• item 1

• item 2

• item 3

1. numbered item

2. item 2

3. item 3

#### Clicker Question #3#

What would happen if I specified a numbered list but put the same number before each list item?

• A) the list would have the same number before each item

• B) markdown would still format it with sequential numbers

• C) markdown wouldn’t know it was a list

• D) normal text with everything on a single line

• E) I’m lost

test it out down here to see…

1. list item

2. list item

3. list item

#### Code Cells#

Whenever you’re writing code, you’ll want to be sure the cell is set to be a code cell

# Cell can also be code.
a = 1
b = 2

# Cells can also have output, that gets printed out below the cell.
c = a - b
print(c)

-1

# If you execute a cell with just a variable name in it, it will also get printed
print(a)
print(c)

1
-1


#### Running Cells#

• The numbers in the square brackets to the left of a cell show which cells have been run, and in what order.

• An asterisk (*) means that the cell is currently running

• You do not need to run cells in order! This is useful for flexibly testing and developing code.

### Coding time#

Write code that outputs the value ‘6’

## YOUR CODE HERE
x=6
print(x)

6


#### Clicker Question #4#

Which of the following best describes you?

• A) I completed the task.

• B) I tried but wasn’t able to complete the task.

• C) I am not sure where to start.

### Accessing Documentation#

Jupyter has useful shortcuts. Add a single ? after a function or class get a window with the documentation, or a double ?? to pull up the source code.
# For example, execute this cell to see the documentation for the 'abs'
type?


### Autocomplete#

Jupyter also has tab complete capacities, which can autocomplete what you are typing, and/or be used to explore what code is available. (Note: Some of this functionality is limited on datahub.)
# Move your cursor to the end of the line, press tab, and a drop menu will appear showing all possible completions
raise

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-26-0f149f1a0a0c> in <module>
1 # Move your cursor to the end of the line, press tab, and a drop menu will appear showing all possible completions
----> 2 raise

RuntimeError: No active exception to reraise

# If there is only one option, tab-complete will auto-complete what you are typing
range


### Installation#

Anaconda is an open-source distribution of Python, focused on scientific computing in Python.
The anaconda website is here.

## The Anaconda Ecosystem#

• Anaconda itself is a distribution - that is, a copy of the Python standard library, included a curated collection of external packages.

• Conda is a package manager, allowing you to download, install, and manage other packages.

### Notes#

• If you are on Mac, you have a native installation of Python. This native installation of Python may be older, will not include the extra packages that you will need for this class, and is best left untouched.

• Windows does not require Python natively and so it is not typically pre-installed.

# You can check which python you are using, and what version it is.
#  Once you have installed anaconda, you should see you are using Python in your anaconda folder
#  Make sure that the version you have is 3.6 (or at least 3.X)
#  Note: these are command-line functions that may not work on windows
!which python
!python --version


### Web Browser#

Jupyter notebooks display in a web browser. They are not hosted on the web, everything is happening locally.

If you click on the url in the browser, you will notice it says ‘localhost’. This means it is connected to something locally, on your computer.

That local connection is to the ‘kernel’.

We’ve had some issues in the past, so we’re trying to be incredibly explicit this quarter so that we’re all on the same page. (And, because this differs from some other courses.)

Rule 1: you must have written, understand, and be able to explain any code you turn in as your own.

Correction: It was for one exam; it was not constant. And it was 6/100 (which is 6% of the class!)

I came into this class knowing absolutely nothing about coding. Being in this position, I have made it my goal to go above and beyond in learning about programming languages that I am unfamiliar with because I personally like a challenge and I love learning new things.

Because coding does not come naturally to me, I plan WAY ahead of time as to when I need to sit down, uninterrupted, to really learn, make mistakes, and test out the code I write in assignments. For example, I plan DAYS ahead of time as to when I need to sit down and complete assignments. Again, because coding does not come naturally to me, I spend on average 2 hours more than the median hours/time spent listed. Not only do I spend hours completing assignments to the best of my ability, but I make sure to test out EACH AND EVERY PIECE of code I wrote in these assignments to make sure my code is “spitting out” what I am expecting, and to show you and the TAs what I was trying to do just in case I get something wrong (because showing work for some points is better than showing no work for 0 points, you know?)

Each student has their method, and planning out WHEN to work and HOW LONG to work on assignments is my method; I just think it is a shame that students resort to cheating when things get tough or they are too lazy to actually learn, because again, that is unfair to me as a student who dedicates time and energy to every assignment in this class.

- Former COGS 18 Student

When can you work with others in COGS 18?

• Coding Labs

• Assignments

Working with others is different than copying from others. It is never acceptable to just ask someone for their answers or their code.

On Coding Labs & Assignments, it is OK to ask one another questions about what you’re working on. It is OK to share screens and talk through your answers.

If you find yourself copying + pasting someone else’s code (from a friend or from the Internet)…you’re probably making a mistake.

When can you NOT work with others?

• Exams

Exams are the only time in this course we ask you to work on material completely on your own.

Exams assess your understanding after you’ve had plenty of practice (in lecture, on coding labs, and on assignments).

It’s your time to show off what you know.

Exams are open notes and open Google.

You can search the Internet for help on concepts.

You are not allowed to ask anyone specific questions from the Exam or post the questions anywhere.

Part of your first Coding Lab will help to make this all as clear as possible!