Class 1: What this course is about. Assignment Read: Chapter 1 Read: Chapter 1 Do: Chapter 1...
-
Upload
lambert-obrien -
Category
Documents
-
view
218 -
download
2
Transcript of Class 1: What this course is about. Assignment Read: Chapter 1 Read: Chapter 1 Do: Chapter 1...
Assignment Assignment
Read: Chapter 1Read: Chapter 1 Do: Chapter 1 ‘workbook’ pages not Do: Chapter 1 ‘workbook’ pages not
finished in classfinished in class You should know:You should know:
How to use the command lineHow to use the command line How to create and save a file How to create and save a file if … elseif … else whilewhile Role of indentingRole of indenting What is a function (e.g., What is a function (e.g., print(), input()print(), input())) What is a parameterWhat is a parameter
In a nutshell (Thread 1)In a nutshell (Thread 1)
This course is about writing This course is about writing computer programs that solve computer programs that solve problemsproblems First step: ‘grok’ the problem. (Look up First step: ‘grok’ the problem. (Look up
the meaning and origin of ‘grok’.)the meaning and origin of ‘grok’.) Second step: write the programSecond step: write the program Third step: make sure the program Third step: make sure the program
correctly solves the problemcorrectly solves the problem
In a nutshell (Thread 2)In a nutshell (Thread 2)
This course is about some of the This course is about some of the high points on the terrain of high points on the terrain of computing. For example:computing. For example: What is computing?What is computing? How does the Internet work?How does the Internet work? How do hardware and software work How do hardware and software work
together?together? … … and moreand more
What is an algorithm?What is an algorithm?
An algorithm is an unambiguous, An algorithm is an unambiguous, step-by-step procedure for solving a step-by-step procedure for solving a problemproblem
A recipe is an example of an A recipe is an example of an algorithmalgorithm
An algorithm provides the design for An algorithm provides the design for a computer programa computer program
What is a computer What is a computer language?language?
A computer language is a way of A computer language is a way of writing down algorithmswriting down algorithms
‘‘High level’ languages are readable, High level’ languages are readable, like natural human languageslike natural human languages
Computer languages are precise Computer languages are precise enough to be executed by enough to be executed by (unthinking) machines(unthinking) machines
All computer languages are All computer languages are fundamentally equivalent in their fundamentally equivalent in their expressive powerexpressive power
What is a program?What is a program?
A program is a set of instructions A program is a set of instructions written in a computer languagewritten in a computer language
A program implements an algorithmA program implements an algorithm A program written in a high-level A program written in a high-level
language may be translated into a language may be translated into a low level language (the natural low level language (the natural language of a computer)language of a computer)
What is a computer?What is a computer?
A computer is a machine which A computer is a machine which executes programs (unlike a lawn executes programs (unlike a lawn mower)mower)
A computer can execute A computer can execute anyany program (unlike a CD-player)program (unlike a CD-player)
Since computers are Universal Since computers are Universal Machines, they are all fundamentally Machines, they are all fundamentally equivalent in computing powerequivalent in computing power
How do you write a How do you write a program?program?
A computer can execute programs that are A computer can execute programs that are tools for creating programstools for creating programs
The programmer’s everyday tools might The programmer’s everyday tools might include:include: editoreditor compilercompiler debuggerdebugger
A suite of such tools is called an integrated A suite of such tools is called an integrated development environment (IDE)development environment (IDE)
We are using the Python language and We are using the Python language and IDLE IDEIDLE IDE
The editorThe editor
An editor is used to write programsAn editor is used to write programs Programs are written in plain textPrograms are written in plain text The file containing the program in a The file containing the program in a
high-level language is called the high-level language is called the source filesource file
A Python source file usually has the A Python source file usually has the extension ‘.py’extension ‘.py’
The interpreterThe interpreter
An interpreter translates from a An interpreter translates from a high-level language to the high-level language to the computer’s language (instruction computer’s language (instruction set)set)
Interpreters usually translate and Interpreters usually translate and execute code line by lineexecute code line by line
A source file can not be interpreted A source file can not be interpreted and executed unless it is and executed unless it is syntactically (grammatically) correctsyntactically (grammatically) correct
The devlopment The devlopment environmentenvironment
We will be working in the Python We will be working in the Python integrated development environment integrated development environment called IDLEcalled IDLE
IDLE contains an interactive IDLE contains an interactive environment in which you can write environment in which you can write and execute instructions line by lineand execute instructions line by line
IDLE also contains an editor to write IDLE also contains an editor to write and store programs and a debugger and store programs and a debugger to help correct programsto help correct programs
The debuggerThe debugger
A debugger allows you to ‘step A debugger allows you to ‘step through’ the program, viewing the through’ the program, viewing the changing valueschanging values
A debugger aids in finding and A debugger aids in finding and correcting logical errors.correcting logical errors.
(The sentence ‘Colorless green ideas (The sentence ‘Colorless green ideas sleep furiously’ is grammatically sleep furiously’ is grammatically correct, but what does it mean? Look correct, but what does it mean? Look in up on the Web.)in up on the Web.)
Panic abatement advicePanic abatement advice
Expect to spend lots of timeExpect to spend lots of time Programmer wisdom: it always takes Programmer wisdom: it always takes
longer than you thinklonger than you think Expect things to go wrongExpect things to go wrong
Murphy’s law of computers: anything Murphy’s law of computers: anything that can’t go wrong, willthat can’t go wrong, will
Don’t panic: every bug has a fixDon’t panic: every bug has a fix
Tips for successTips for success
Start every assignment earlyStart every assignment early Don’t fall behindDon’t fall behind Ask if you don’t knowAsk if you don’t know Do your own workDo your own work
Getting helpGetting help
Use the online help systemUse the online help system Every TA and instructor has office Every TA and instructor has office
hourshours There are tutors available (check There are tutors available (check
the course web site)the course web site) My contact info:My contact info:
Barry CohenBarry Cohen 3503 GITC3503 GITC [email protected]@njit.edu Tues, Thurs 2:30-3:30Tues, Thurs 2:30-3:30
GradingGrading
Homework (6) Homework (6) 15% 15% Projects (2)Projects (2) 15% 15% Midterm 1 20%Midterm 1 20% Midterm 2 20%Midterm 2 20% Final 25%Final 25% ParticipationParticipation 5% 5% All sections have same work and testsAll sections have same work and tests Course is graded on a curveCourse is graded on a curve
AttendanceAttendance
Attendance is mandatory (you are Attendance is mandatory (you are asked to sign in). Five absences will asked to sign in). Five absences will lead to withdrawallead to withdrawal
Arriving late or leaving early counts Arriving late or leaving early counts for ½ of an absencefor ½ of an absence
HomeworkHomework
HW assignments are approximately bi-HW assignments are approximately bi-weeklyweekly
HWs are handed in at the start of classHWs are handed in at the start of class No late HWs will be acceptedNo late HWs will be accepted Every HW must be in hard copy – code Every HW must be in hard copy – code
and output, neatly printed and stapledand output, neatly printed and stapled Every HW must have student name and Every HW must have student name and
SS#, date, HW # section #SS#, date, HW # section #
HonestyHonesty
Cheating on an exam will result in Cheating on an exam will result in failing the coursefailing the course
You may discuss HW problems with You may discuss HW problems with each othereach other
You may not take credit for You may not take credit for something you did not dosomething you did not do
Logging OnLogging On
Linux/Unix, Mac or WindowsLinux/Unix, Mac or Windows UCIDUCID PasswordPassword
Password problem?Password problem? Unattended Password Reset (UPR)Unattended Password Reset (UPR)
http://mypassword.njit.eduhttp://mypassword.njit.edu
Introduction To PythonIntroduction To Python
What is Python?What is Python? Very high level language (HLL)Very high level language (HLL) Scripting languageScripting language
Why use Python?Why use Python? Powerful and fastPowerful and fast Runs everywhereRuns everywhere Easy to learnEasy to learn Easy to readEasy to read Encourages good programming practicesEncourages good programming practices
The Python InterpreterThe Python Interpreter
Linux/UnixLinux/Unix Open a terminal windowOpen a terminal window Type ‘python’ or ‘idle3’ at a command Type ‘python’ or ‘idle3’ at a command
promptprompt Or double click iconOr double click icon
WindowsWindows Go to Start > Programs > Python3 > IdleGo to Start > Programs > Python3 > Idle Or double click iconOr double click icon
MacMac Open from terminal or double click iconOpen from terminal or double click icon
Python As A CalculatorPython As A Calculator
Python can perform all basic Python can perform all basic arithmetic operationsarithmetic operations
How many minutes in a year?How many minutes in a year? How many seconds since the How many seconds since the
universe began 13 billion years ago?universe began 13 billion years ago?
The IDLE environmentThe IDLE environment You can use IDLE to assign values to an identifier (i.e., a You can use IDLE to assign values to an identifier (i.e., a
name)name)>>> x = 5>>> x = 5 An IDLE session has a memoryAn IDLE session has a memory>>> x>>> x55>>> y = x>>> y = x>>> y>>> y55 You can the change the value assigned to an identifierYou can the change the value assigned to an identifier>>> x = 'five'>>> x = 'five'>>> x>>> x'five''five'
Your First Python Your First Python ProgramProgram
Type Type print(‘Hello, World!’)print(‘Hello, World!’) and and then press the enter keythen press the enter key
The Python interpreter prints ‘Hello, The Python interpreter prints ‘Hello, World!’ on the screenWorld!’ on the screen
More about Hello, WorldMore about Hello, World
print() print() is a functionis a function A function is a named block of codeA function is a named block of code A function hides how it works from the outside A function hides how it works from the outside
worldworld ‘‘Hello, World’Hello, World’ is a parameter is a parameter
A parameter is ‘handed’ to a functionA parameter is ‘handed’ to a function A parameter is in parens, after the function A parameter is in parens, after the function
namename Try Try print ()print () and and (‘‘)(‘‘) Try Try print (‘hello‘, ‘and goodbye‘)print (‘hello‘, ‘and goodbye‘) Try Try print print