import numpy as np
= np.array ([2, 3, 5, 7, 11, 13, 17, 19, 23, 29])
x = np.sum(x)
y print(f"the sum of {x} is {y}")
Set up your computer
MacOS, Windows, or Linux?
Yes.
Everything we do in this course you can do using a computer that runs MacOS, or Windows, or Linux. Personally I am most familiar with MacOS and Linux.
Python
We will be using Python in this course.
- download and install Python
Code Editor
Python code lives in plain text files that by convention have a .py
extension, and you can view and edit them in any editor you want. There are many to choose from. I use Visual Studio Code which is free and available on MacOS, Windows, and Linux. You can use whatever you wish. In class I will be using Visual Studio Code, and I will show you how to use some of its more useful features for Python programming and data analysis.
- download and install Visual Studio Code
Git/GitHub
We will be covering code versioning using Git and GitHub, so you should:
Check your setup
Assuming you have installed Python and VSCode:
- create a new folder somewhere on your computer’s file system and name it
Psych_9040
- launch VSCode
- in the welcome screen there is an item under “Start” called “Open Folder …” — click it and navigate to the
Psych_9040
folder you created in step 1 above, and select it - now click on “New File …” to create a new empty file, select “Text File” from the dropdown menu
- In the VSCode “File” menu select “Save” and name the file
hello.py
; VSCode may ask you if you want to install the Python extension, click Yes - If you didn’t get asked about installing the Python extension, do it manually: type CMD-Shift-P (MacOS) or CTRL-Shift-P (Windows/Linux) to launch the Command Palette and enter
Extensions: Install Extensions
and select the item from the dropdown menu by clicking it with the mouse or by typing Enter/Return; the Extension browser will have opened as a column on the left hand side of the VSCode window. At the top there is an empty text entry field. TypePython
; click “Install” on the one called “Python” (Python extension for Visual Studio Code) from Microsoft - type the following in your
hello.py
file:
launch the Command Palette and type in
Python: Create Environment
and select that item in the dropdown listselect the “Venv” option to create a
.venv
virtual environment in the current workspaceselect your preferred Python interpreter from the dropdown list
bring up the Command Palette again and type
Terminal: Create New Rerminal
and select it; (note: if you are on Windows, click the down-arrow next to the+
and select “Select Default Profile” and then select “Command Prompt”)… then close the terminal and re-open it via the Command Palettein the Terminal that opens up, type
pip install numpy
and then Return/Enternow type
python hello.py
and Return/Enter
You should see the following output in the Terminal:
the sum of [ 2 3 5 7 11 13 17 19 23 29] is 129