# Today s Topics... Intro to Computer Science (cont.) Python exercise. Reading Assignment. Ch 1: 1.5 (through 1.5.2) Lecture Notes CPSC 121 (Fall 2011)

N/A
N/A
Protected

Share "Today s Topics... Intro to Computer Science (cont.) Python exercise. Reading Assignment. Ch 1: 1.5 (through 1.5.2) Lecture Notes CPSC 121 (Fall 2011)"

Copied!
8
0
0

Full text

(1)

Today’s Topics ...

• Intro to Computer Science (cont.)

(2)

### Computation (cont.)

What “parts” do recipes usually have?

• A description (the requirements)

• An ingredient list (the input)

• A set of ordered steps to perform (a procedure)

A recipe is an example of procedural (imperative) knowledge

• Knowledge of how to perform some task (or process)

• A recipe gives a procedure to create (“compute”) an output from input

• Declarative knowledge only tells us about the output, not how to produce it 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

(3)

At the 10,000 foot level, as programmers

• We figure out what the instructions should be (the algorithm)

• We write them down as a program (in a programming language)

• We give the program to a computer with input data

• The computer runs the program on input data (the computation process)

• And supplies the output

A computer is a general-purpose machine (aka “universal machine”)

• Instead of being able to execute only one or a few types of processes – e.g., like a toaster or a car wash

• A computer can perform any computation – According to the Church-Turing Thesis

– Everything computable is computable by a “Turing Machine”

(4)

### Another example ...

Consider the following two statements 1. √x is y such that y2 = x for y ≥ 0

2. 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

What type of knowledge do each of these represent?

Another way to think of computation ... (from Abelson & Sussman)

• Computation is like a sorcerer’s idea of a magical spirit – Cannot be seen or touched, is not composed of matter

• The programs we use to conjure computations are like a sorcerer’s spells – From symbolic expressions in arcane, esoteric programming langauges – Used to prescribe the tasks we want our computations to perform

• We’ll conjure our (computational) spirits in a magical language called Python

• Learning to program is considerably less dangerous than learning sorcery – Computational “spirits” are conveniently contained within a computer In case you aren’t convinced ...

def square_root(x, d):

g = 1 # not a great guess for i in range(1, d):

(5)

### 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

• If you can’t login, send email to Jason Schnagl (schnagl@gonzaga.edu, PC 216, 313-3534)

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

(6)

After you enter statements, you can “run” the module

• You need to save the module file first

• You might create a cpsc121 folder and save the file, e.g., as lab1.py

• Run the module by clicking Run > Run Modulein the editor (not the shell)

• You can also hit the F5 shortcut key

• After you run the module, you’ll see “RESTART” in the Python Shell

• This is where you wold see the “output” of your program Print statements

• The Python Shell prints the result of every statement entered

• E.g., >>> 3 + 4 prints 7

• In a module, you have to explicitly tell Python to print the result of a statement

• E.g., print(3 + 4) prints 7 in the Python Shell

(7)

Basic file management

• Double-click on the “Home” folder icon on the desktop

• For me, this is “bowers’s Home” Printing

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

Don’t forget to logout!

• Select System > Log Out from the menu bar on the desktop

(8)

### 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

References

Related documents

Resume recovery feature of Stellar Phoenix Photo Recovery allows you to recover photos, audio and video files using saved scan information file or image file.. You can use the

The question isn’t what forces the truth of the conclusion unerringly, but rather what in the premises makes the conclusion truth-apt given that the nature of those facts is

College Mathematics (3 Credits) Biology (6 Credits) Arts and Humanities 3 Arts and Humanities 3 TOTAL 35 20 8.00 **Total up RED # ** Excess credits 0.00 8.00 Analyzing and

The companies Berlin Partner GmbH and ZukunftsAgentur Branden- burg GmbH (Brandenburg Economic Development Board) support with a large range of services, from recruiting

necessary classification strategies used for recognition area unit Artificial Neural Networks (ANN),.. Support Vector Machine (SVM), Hidden Markov Models (HMM), Deep

• Taxpayers subject to the provisions of Title II of the Income Tax Law (ITL) which have declared taxable income of \$644,599,005 or more in the immediately preceding tax

Silicon Valley San Francisco San Francisco Peninsula Austin Seattle Raleigh-Durham Salt Lake City Denver Boston Baltimore New York Washington DC San Diego Pittsburgh

[r]

Note that the financial aid administrator at your school may require you to provide proof that your parent is a dislocated worker, if you answered “Yes” to question 85, or that you

For the past 20 years we have helped IT administrators deploy at the file level, allowing them to easily modify individual files on client systems at any time, resume

To further illustrate the importance of analyzing historical CDS trading patterns as opposed to merely looking at the recent or spot CDS spreads, we enhance our previous study

With the passage in 2009 of Bill 133, which amended both the Family Law Act (FLA) and the Pension Benefits Act (PBA), and the promulgation of new Regulations in 2011 under

WARNING: Due to the possibility of an explosion which could result in personal injury and/or property damage, never allow carbon dioxide cylinder and it’s contents to reach

I have visited the farms/areas where the crops are grown, and can verify that there has not been any cultivation of areas with a high conservation value since the operator

features of an object) of primitive type are given default values.. int age; // Initialized

By pricing the elastic traffic separately with spot transit that has no SLAs, tier-1 ISPs are able to adopt a lower price, which in turns attracts even more demand and

  ParEEoning    Manager spreads namespace across Owners by assigning leases    Consistency  

Motivation Problem statement Simulation scenario Results of performance prediction ConclusionsB. A study on machine learning and regression based models for performance

The algorithm will only match applicants employers preferred for NESP positions to NESP positions and applicants employers preferred for NETP positions to NETP positions. This way

In the previous sections, we dis- cuss the expectation that a neural network exploiting the fractional convolution should perform slightly worse than a pure binary (1-bit weights

Steele of Stanford University Online High said that shift is already underway: In a recent survey of ASCA members, she and her colleagues found that more than one-fourth of

• Our goal is to make Pittsburgh Public Schools First Choice by offering a portfolio of quality school options that promote high student achievement in the most equitable and