CSC 015: FUNDAMENTALS OF COMPUTER SCIENCE I€¦ · CSC 015: FUNDAMENTALS OF COMPUTER SCIENCE I ... • Overviewof Programming Language. ... 1 Introduction to Computer Systems 0.5

Post on 16-May-2018

220 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

9/7/16 CSC15 - Python

1D R . B O T A N GA S S I S T A N T P R O F E S S O R

H O F S T R A U N I V E R S I T Y

CSC 015: FUNDAMENTALS OF COMPUTER SCIENCE I

Lecture 1: Class Introduction

OUTLINE

• What is Computer Science?• What is this Class about?• Introduction to Computer Systems• Overview of Programming Language

WHAT IS COMPUTER SCIENCE (CS)

• CS is the study of how to write computer programs (programming)??• No. Programming is a big part of CS, but it is not the most

important part.

• CS is posing a problem in such a way that a computer can help us solve it.

• CS is the study of algorithms to solve problems with their hardware (Computer Design) and software (Programming) realizations.

WHY CS: I

The computer is incredibly fast, accurate, and stupid. Man is unbelievably slow, inaccurate, and brilliant. The marriage of the two is a force beyond calculation.

-Leo Cherne

WHY CS: II

“Everybody in the country should learn how to program a computer... Because it teaches you how to think.”

-Steve Jobs

WHY CS: III

• CS connects to other fields:• Mathematics: closely-related to CS, theory of computation,

equation solutions, etc.• Physics: Hypothesis testing, simulation, experimental data

processing, etc.• Biology: data collection, data analysis, etc.• Robotics: computer vision, path planning, autonomous

control, etc.• Electrical Engineering: computer-aided design (CAD),

simulation, embedded systems, etc.• …

WHAT IS THIS CLASS ABOUT?

7

• The purpose is to use programming language as a tool to solve the problems:• Develop a basic understanding of computer

programming;• Master a very high-level computer programming

language: Python;• Develop problem solving skills with computer

program design.

WHAT IS THIS CLASS ABOUT?

8

# Topic* # of Weeks1 Introduction to Computer Systems 0.52 Variables, Expressions, Data Types 1.53 Control Flow: Conditions and Loops 14 File Operations 15 Array, List 26 Function Calls 27 Recursion 18 Algorithm Design I 1.59 Algorithm Design II 1.5

10 Introduction to Object-Oriented Design 2

Topics will be covered in this class:

WHAT YOU NEED FOR THIS CLASS

9

• Instructor: Dr. Bo Tang Bo.Tang@HOFSTRA.EDUAdams 104

• Office Hrs: Tuesday 1:00 PM – 2:00 PM

• Labs: Adams 204 Account & Your Own Laptop

• Text:• John M. Zelle, Python Programming

– an Introduction to Computer Science (2e)

• Slides: in Blackboard.

YOUR LAPTOP!

• CPU >1.0Ghz• RAM >1GB• Disk Space >1GB

• Install Python 2.7: https://www.python.org/• Windows• Mac OS• Linux• Other Platforms

GRADING POLICY: I

• Grading• Two Midterm Exams (Open Book) ~30%

� Midterm I: Early Oct. Midterm II: Early Nov.• Final Exam (Open Book) ~20%

� Early December• Assignments (12-13) ~50%

� Due date specified in Blackboard� Note: including mini-projects

• Grades will be posted on Blackboard• Must submit email request for change of grade within one

week after grades posted (for each assignment)

GRADING POLICY: II

• Final Letter Grade will be determined byA = 91 to 100 or top 10% of class,A- = 85 to 90 or top 20% of class,

B+ = 80 to 84 or top 30% of class,B = 75 to 79 or top 40% of class,B- = 70 to 74 or top 50% of class,

C+ = 65 to 69 or top 60% of class,C = 60 to 64 or top 70% of class,C- = 55 to 59 or top 80% of class,

D = 45 to 54,F = below 45.

Note: You will get A if your final score is 88, but in top 10% of class.

You will get F if and only if your final score is below 45.

LATE POLICY

• Late Penalty Tabular

1 – day* late 20%

2 – day late 40%

3 – day late 60%

4 – day late 80%

5 – day late 100%

* Day – Business Day (Holiday Excluded, Sick Day with Documents excluded)

Example:Jack’s HW1 is 2 days late and scores 80 out of 100 points.What’s the final points he receives for HW1?

80 points * (1-40%) = 48points.

INTRODUCTION TO COMPUTER SYSTEMS

• Computers:• Hardware• Software

INTRODUCTION TO COMPUTER SYSTEMS

• Computers:• Hardware• Software

Functional View of a Computer

INSIDE THE CPU

• Fetch-Execute Cycle• First load the instruction sets to instruction cache from memory• Fetch an instruction from the cache• Decode the instruction to see what it represents• Appropriate action carries out.• Next instruction fetches, decodes, and executes.• repeat!

INTRODUCTION TO COMPUTER SYSTEMS

• Computers:• Hardware• Software

PROGRAMMING LANGUAGE: I

• Programming is to write the instructions that the computer will follow.

• High-level computer languages• Designed to be used and understood by humans: C, C++,

Java, Python, etc.

• Low-level language• Understood by human, but difficult to design: Assembly.

• Machine Language• Only be understood by CPU.

PROGRAMMING LANGUAGE: II

• Example: Add two numbers

• Low-level language (Assembly):• Load the number from memory location 2001 into the CPU

(mov ax, 2001)• Load the number from memory location 2002 into the CPU

(mov bx, 2002)• Add the two numbers in the CPU (add ax, bx)• Store the result into location 2003 (mov 2003, ax)

• Machine language:• A set of binary numbers (1’s and 0’s)

PROGRAMMING LANGUAGE: III

• High-level language: c = a + b• This needs to be translated (via compilers or interpreters) into

machine language that the computer can execute.

• Python that we will learn in this class is a very high-level programming language.• Vocabulary à Key words (just a few)• Grammar à Syntax: expressions, data structures, etc.

WHAT IS A PROGRAM

• A program is a sequence of instructions that specifies how to perform a computation.

• Basic instructions appear in about every language:• input: get data from keyboard, a file, or some devices• output: Display data on the screen or send data to a file.• math: perform basic mathematical operations• conditional execution: check for certain conditions and

execute particular sequence of statements.• repetition: perform some actions repeatedly, usually with

some variation.

INTRODUCTION TO PYTHON

When you start Python, you will see something like:

Python 2.7.9 (default, Dec 10 2014, 12:28:03) [MSC v.1500 64 bit (AMD64)] on win32

Type "copyright", "credits" or "license()" for more information.

>>>

INTRODUCTION TO PYTHON

The “>>>” is a Python prompt indicating that Python is ready for us to give it a command. These commands are called statements.

>>> print("Hello, world“) Hello, world>>> print(2+3)5>>> print("2+3=", 2+3)2+3= 5>>>

INTRODUCTION TO PYTHON

Usually we want to execute several statements together that solve a common problem. One way to do this is to use a function.

>>> def hello():name = raw_input(“Please enter your name: “)msg = “Hello “ + name + “. Welcome to CSC15!”print(msg)

INTRODUCTION TO PYTHON

def hello():name = raw_input(“Please enter your name: “)msg = “Hello “ + name + “. Welcome to CSC15!”print(msg)

qBeginning of the definition of a function called hello

INTRODUCTION TO PYTHON

def hello():name = raw_input(“Please enter your name: “)msg = “Hello “ + name + “. Welcome to CSC15!”print(msg)

qraw_input(“”) is a function to take user’s input, and the quoted information is displayed.

qname is an example of a variable. Here, it stores user’s input.

qA variable is used to assign a name to a value so that we can refer to it later.

INTRODUCTION TO PYTHON

def hello():name = raw_input(“Please enter your name: “)msg = “Hello “ + name + “. Welcome to CSC15!”print(msg)

qmsg is a new variable that constructs a new string with the value of name.

INTRODUCTION TO PYTHON

def hello():name = raw_input(“Please enter your name: “)msg = “Hello “ + name + “. Welcome to CSC15!”print(msg)

qprint() is a function causing Python to print a message.

INTRODUCTION TO PYTHON

>>> def hello():name = raw_input(“Please enter your name: “)msg = “Hello “ + name + “. Welcome to CSC15!”print(msg)

• Notice that nothing has happened yet! We’ve defined the function, but we haven’t told Python to perform the function!

• A function is invoked by typing its name.>>> hello()Please enter your name: JackHello Jack. Welcome to CSC15!>>> • When we exit the Python prompt, the functions we’ve

defined cease to exist! • Use module files or scripts that are saved on disk.

INTRODUCTION TO PYTHON

# File: hello.py# A simple program asks name and print hello msg# Input and Output

def hello():name = raw_input(“Please enter your name: “)msg = “Hello “ + name + “. Welcome to CSC15!”print(msg)

hello()

INTRODUCTION TO PYTHON

# File: hello.py# A simple program asks name and print hello msg# Input and Output

qLines that start with # are called commentsqIntended for human readers and ignored by PythonqPython skips text from # to end of line

INTRODUCTION TO PYTHON

def hello():name = raw_input(“Please enter your name: “)msg = “Hello “ + name + “. Welcome to CSC15!”print(msg)

hello ()qThis last line tells Python to execute the code in the

function hello.

SUMMARY: COMPUTER SYSTEMS

• Hardware:• Input/output devices, CPU, Memory, Hard Disks, etc.

• Software:• Programming/coding to provide instructions to computer.

• Example of hello.py illustrates how the program take user’s input from keyboard, and output desired messages.

• Next Week: elements of programs (variables, expressions, operators, etc.), and practice to write Python programs.

SOMETHING YOU NEED TO KNOW WHEN YOU START PROGRAMMING

1. You learn by doing. (The only way to get better at programming).

2. Programming isn’t like studying for a test.3. Let go of your emotions.4. Trying to understand everything is a lost cause.5. A right way to ask for help:

a) Explain exactly what you think should be happeningb) Explain exactly what is actually happeningc) Explain why you think it should be working differently.

6. You don’t need to be a math genius.

SOMETHING YOU NEED TO KNOW WHEN YOU START PROGRAMMING

7. It is ok to admit what don’t know.8. Programmers never stop learning.9. Make the computer think like a human.

Ken Mazaika, Quora.com

top related