Introduction to CS21

Welcome to CS21. This course is designed to have a mix of lecture and hands on in class lab exercises. This page will review some of the tools we will use during the labs and help you get set up with the system in the CS department.

Staff Introductions

Who should take this course?

This course is designed for students with little or no programming experience. If you have taken a computer science course previously or taught yourself basic programming skill in any language, even if it wasn't python, you may find this course too slow. Students with prior programming experience are encouraged to contact Prof. Andrew Danner to take the CS Placement exam to see if CS21 is the proper fit.

Creating accounts

The CS machines in the Sci 256, Sci 240, the overflow lab (Sci 238) and Clothier Lab are on a separate network than the machines managed by ITS. You need a separate account with a separate password to access these machines. If you do not have an account, please see Jeff Knerr to get a user agreement form.

The first time you login, you will likely want to change your randomly assigned password. Open a terminal window by clicking the terminal button  on the bottom toolbar. At the $ prompt, type passwd, press enter and follow the instructions. Note that when you are typing your old or new password, nothing will be displayed to the screen (no \*'s and certainly not your password). The program will not allow you to pick a password that it thinks is too short or too easy to guess. If you ever forget your password, you can reset it by going to CS password reset page.

Your student ID has an RFID tag that can allow you access to the building and the labs after hours. This year, you should have automatically have access to the lab space by enrolling in the course. If you are having trouble with the card readers, please let me know.

Adding the course, switching sections

If you are looking to add this course or switch to a different section, please talk to Lauri Courtenay before you leave class today. Lauri manages the waitlist for all sections. We will try to provide you an answer to your registration related questions as soon as possible. If you are already on the waitlist, please sign in on form provided in class.

Course Webpage

The course webpage is updated regularly and contains recent course announcements, links to inclass exercises, lab assignments, quiz topics, and other less dynamic course information including office hours, ninja sessions, and python tips. Bookmark the website in firefox or chrome and refer to it regularly. On the occasional occurrence that a lab or quiz topics are not immediately available, it is sometimes useful to check if the other sections have the links posted. All sections have the same quiz dates and lab assignments.

Piazza

This semester, we are using Piazza to manage course discussions and announcements. If you are registered for the course, you should get an email soon about registering for Piazza. You are encouraged to ask questions on the Piazza forums instead of sending us emails directly. Please review the Piazza guidelines on how to write a good Piazza post.

Labs

This course has a mandatory lab section. Attendance is required unless you have completed and submitted the lab for the week prior to the start of lab. Labs started Tuesday and Lab 00 is due Saturday night.

What is Computer Science?

Computer science focuses on two primary questions; what can be computed, and how efficiently can computers solve problems? The answers are more nuanced than "everything", and "really fast". At the core of the discipline is algorithms. Algorithms are concise descriptions of how to solve a problem computationally. Algorithms can be implemented in a programming language and interpreted by computer hardware to automate computation. Programming is NOT the core of computer science. Programming is a way to automate and test the creative thought process that resulted in an algorithm. Programming is one tool at the disposal of computer scientists, but it is not the only tool. This course will teach you how to discover, develop, and write clear computational solutions to, often times non-computationally themed, problems. To check your thinking, you will also learn programming, debugging, and testing skills.

What is python?

Python is the programming language we will use to implement and test our algorithms. It is relatively easy to learn, even for people not in computer science or related fields. It is free to download and it runs on many platforms including linux, Mac OSX, and Windows. It's pretty fun to learn and we can get started right away!

Python shell vs linux shell

In this course (and many other CS courses) we will be using the terminal window frequently. You can open a terminal window by clicking the terminal button  on the toolbar on the bottom of the screen. The terminal window is sometimes called the console window, an xterm, a shell, a command shell, or my personal favorite, the black screen (if you adjust the preferences, your black screen may be a different color). These are all names for pretty much the same thing. Typing certain commands in the terminal tells the computer to perform certain actions. We will examine a few commands over the next few weeks, but there are literally thousands of possible commands you can run from the terminal. We will not cover all of them.

By default, the terminal starts in a linux shell with a prompt that looks (by default), something like

cumin[~]$

The name cumin is the hostname or name of the computer, and is likely different for each student. This linux prompt indicates that the terminal is ready to accept linux commands. Lab 00 asks you to explore some of these linux commands. We'll be practicing the commands in class and lab throughout the semester.

The python3 command tells linux to start the python shell. This program changes the terminal prompt to

>>>

and now the terminal is ready to accept python commands

cumin[~]$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("welcome to comp. sci.")
welcome to comp. sci.

>>> 2+2
4

>>> 4*5.
20.0

>>>quit()
cumin[~]$

In this mode, python commands are interpreted one line at a time and the result is printed to the screen. Typing quit() in the python shell quits the python interpreter and returns the user to the linux shell. Learn to recognize what program is running by inspecting the prompt.

update21 and handin21

Eventually, we will be saving our python code in files. You will also be using two commands regularly through the course to get and submit files for the course: update21 and handin21. Try to run them now at the linux prompt. You should run update21 before starting each lab assignment and handin21 to turn in lab assignments. You can run them as often as you like. update21 will not clobber files you modify after running update21 and handin21 can submit the same lab multiple times. Each handin submission is stored separately, but only most recent copy submitted prior to the deadline will be graded. You may continue to submit after the deadline, but these submissions will be ignored.

If update21 or handin21 does not work for you or it says you are not allowed to run these programs, email me. It is usually my fault, not yours. I may need to add you to the class roster, change handin or change permissions on a directory.

Writing a full python program

If update21 worked for you, it should have created an empty welcome.py file in your ~/cs21/inclass/w01-intro directory. Let's practice some basic linux commands to:

  1. navigate to the correct folder using cd
  2. list the contents of a folder using ls
  3. open a file for editing using atom
  4. writing, saving, and running our first python program.
cheese[~]$ cd

cheese[~]$ ls             
Desktop/  Documents/   cs21/  

cheese[~]$ cd cs21

cheese[cs21]$ ls
inclass/  labs/

cheese[cs21]$ cd inclass/

cheese[inclass]$ ls
w01-intro/

cheese[inclass]$ cd w01-intro/

cheese[w01-intro]$ ls
welcome.py

cheese[w01-intro]$ atom ./

Inside the atom editor, click on the welcome.py to open it for editing. Type in the following content as your first python program. Use your name instead of A. Danner to take credit for your work.

"""
 My first python program
 A. Danner
 January 2019
"""

def main():
    print("Welcome to cs21.")

main()

Save the file by pressing CTRL-S, and run the program by typing python3 welcome.py in the terminal. Did it work? If not, what errors did you observe?