Docsity

Introduction - Computer Science - Lecture Notes, Study notes of Computer Science

Partial preview of the text

Download Introduction - Computer Science - Lecture Notes and more Study notes Computer Science in PDF only on Docsity!

Today ...

  • Using the lab computers
  • Intro to Computer Science

Homework

  • HW 1 due Wed ... (no class Monday!)

Reading Assignment

  • None yet

Getting started in the CS Lab

The CS lab guide

  • http://www.cs.gonzaga.edu/startup_guide.html

The computers run the Linux (CentOS) operating system

  • Similar to MS Windows and MacOS, but different

Login using GU userid and password

  • If you can’t login, send email to Jason Schnagl ([email protected], PC 216, 313-3534)

Basic file management

  • Double-click on the “Home” folder icon on the desktop
  • For me, this is “bowers’s Home”
  • Add a folder called “cpsc121”

Double-click on the IDLE 3.2 desktop icon

  • Starts a basic Python Shell
  • Shows a prompt “>>>” called a “chevron”
  • You can start typing statements at the prompt (e.g., 3+4)

IDLE includes a simple code editor

  • From the Python Shell window click File > New Window
  • In the new window, note there is no prompt
  • You can enter statements into the window
  • You are creating/editing a Python “module” (more later)

Printing

  • Select File > Print Window from within Python Shell or the editor and select the Default Printer

Don’t forget to logout!

  • You can use the “Logout” icon on the desktop
  • Or select System > Log Out from the menu bar on the desktop
  • Don’t need to shut down the computer, but do need to log out

Exercise: The “Hello World!” Program

By convention, the first program written when learning a new langauge

print("Hello World!") Hello World!

  • In Python, this is a super-easy program to write

Exercise:

  1. Start IDLE
  2. Using the Python Shell, use print to display “Hello World!”
  3. Try print with other strings
  4. Send your session to the printer
  5. Repeat the above, but use the editor instead of the Python Shell
  6. Put your name on both hardcopies and turn them in

Notes:

  • print is a function
  • We call the print function
  • We pass arguments to function calls
  • The number of arguments depends on the function

Another example ...

Consider the following two statements

x is y such that y^2 = x for y ≥ 0

  1. To find an approximation of

x, make a guess g, improve the guess by averaging g and x/g, and continue until g is good enough

  • “Heron’s Method” (Hero of Alexandria – Greek mathematician/engineer)

What type of knowledge do each of these represent?

The procedure in Python ... def square_root(x, d): g = 1 # not a great guess for i in range(1, d): g = (g + (x/g))/ return g

Computation is a process for performing certain tasks

  • Like the process of making your favorite dessert
  • We typically think of computation as a process that manipulates data
  • That is, computing (deriving) new data from existing data

Computation is directed by a series of instructions

  • Often called procedures, methods, or algorithms
  • We write these down using a programming language
  • A procedure written in a programming language is called a program
  • Computers execute programs for us