Welcome to Introduction to
Welcome to Introduction to
Computers and Programming
Computers and Programming
Course
Course
using Python
using Python
V22.0002,
V22.0002,
Section 3
Section 3
, Spring 2010
, Spring 2010
Course Introduction
Course Introduction
Professor: Sana Odeh
Professor: Sana Odeh
[email protected]
[email protected]
Office hours:
Office hours:
Mondays
Mondays
2:00 pm - 4 pm
2:00 pm - 4 pm
,
,
room 321 in WWH, or
room 321 in WWH, or
at other times by appointment
Road Map for Today
Road Map for Today
•
Course Description
• What material will we cover? • What am I getting myself into?
•
Administrative Issues
• Course Web Page, Text Book, Exams, Office Hours, Homework, Grading, Cheating Policy, etc.
•
Syllabus
•
Intro. to Programming Languages and Python
Course Prerequisites
Course Prerequisites
• Prerequisites:
• This course in intended for students who have no previous experience in programming
• (No prior programming experience required (Really)
• The focus of the course is to provide you with an elementary introduction to programming in Python.
• It’s open to all students who are interested in programming from any field or
background (such as Film, journalism, economics, education, math, biology and so on.)
• Who should be taking this course:
• Students who are interested in programming
• Students who want to take a computer science minors or Web Applications and Programming minor (http://cs.nyu.edu/web/Academic/Undergrad/minors.html) • Students who want to switch to a computer science major
• You must get a c or better in this class to take further computer science
classes.
• Who should NOT be taking this course
• Students trying to get out of taking a math requirement. This class may be more difficult than the math you are trying to avoid.
4
Course Description
Course Description
• In this course, we will study the fundamentals of computer
programming ... one of the towering intellectual achievements of the 20th century. We will design, code, and debug programs using
Python as we explore these concepts.
• Python is a popular programming language, widely used in business, entertainments, science, arts, games, mobile apps.
• Famous companies that use Python are Google, Pixar, Disney, NASA, and Yahoo!
This is all Computer Science?
This is all Computer Science?
6
Why learn programming continued
Why learn programming continued
…
…
?
?
•
The purpose of this course is to teach you about
computing, but particularly, programming in Python (a
powerful, widely-used programming language).
•
Why care about computers and programming?
• Growing field with great opportunity (read: $) • Creative
• Challenging
• Fun (Developing Games for example)
• Enabling/Empowering, creative and innovative technology
What the class is really about
What the class is really about
Course Objectives:
1. We will learn to program in Python.
• This includes all the rules (SYNTAX) that are specific to Python.
2. We will cover the fundamentals of programming (shared concepts in all high level programming languages):
• Variables and data types • Control Structure
• Repetition • Functions • Data Structure
• Input and output (including files I/O)
• Introduction to GUI (Graphical User Interface) programming:
• Learn how to write programs integrating, graphics, and sound.
• Introduction to web programming (CGI):
8
Book Chapters to be covered in this class:
Most readings will be assigned from the Visual Quick start book since it is using the current python version 3.
But, it will be important to do similar readings from the Gaddis book since it provides more explanations about programming concepts covered in this class.
•Chapter 1 Introduction to Computers and Programming
•Chapters 2 Arithmetic, variables and data types (Strings)s
•Chapters 3 Writing Programs
•Chapter 4 Control Structure and Repetition
•Chapter 5 Functions
•Chapter 6: Strings
•Chapter 7: Data Structures (Tuples, lists, Dictionaries)
•Chapter 8:Input and output (File I/O)
•Chapter 9: Exceptions
Additional topics, depending on time (Gaddis book):
Chapter 12: GUI Programming
CGI Web Programming: An introduction to using Python for writing scripts to
Learn the Core Concepts of all
Learn the Core Concepts of all
Programming Languages
Programming Languages
•
There are many programming languages available:
• C++, C, Python, Ada, Perl, Ruby, Python.
•
All of these languages share core concepts.
•
By focusing on these concepts, you are better able to
learn any programming language.
•
Note: Python is an object oriented programming
language. However, we will not touch upon the concepts
which categorize it as one.
•
Python is
easy to learn and also easy to develop programs
with graphics, sound capabilities for games, animation
for Arts and sciences and output programs for the web
(CGI).
Python is much easier to learn than
Python is much easier to learn than
other programming languages
other programming languages
let
let’’s see hows see how can print one linecan print one line using Python and pythonusing Python and python what do you think?
what do you think? // Hello Program in Python
public class welcome1 {
public static void main( S tring args[] ) {
System.out.println(“Hello students and welcome to programming " ); } // end method main
} // end class Welcome1
10
# Hello program in Python
An Example: Loops
An Example: Loops
•Python
has a construct called a
while loop
that enables a
program to repeat actions over and over.
•
Most other languages also have a for loop.
•
Hence, by learning about for loops in
Python, you can
easily learn while loops in C, C++, Python, PythonScript,
Perl.
12
Here is a
Here is a
Sample Program
Sample Program
in Python
in Python
# Sample Program in Python Guess the secret word """ This program will ask the user to guess the secret word repeat until the user gets the correct answer """
repeat= True secret= "Python" tries = 3
while repeat:
guess = input("Guess the secret word to win $100: Please enter your guess here : ") tries = tries - 1
if guess == secret: print ()
print ("Congratulations! You won $100!") repeat = False
else:
print ("Wrong guess!") if tries == 0:
print ()
print ("Game is over. You only have three tries") repeat = False
else: print ()
print ("Keep trying: You have %d tries remaining" % tries)
This program will
try to guess the
secret word in 3
tries to win $100.
In a few weeks, it
will all make sense
(I promise!)
Administrative Matters
Course Web Site
Course Web Site
•
Course web site is available at:
http://www.cs.nyu.edu/courses/spring010/V22.0002-003/index.html
Web site contains the following information:
• Administrative information • Course Syllabus • Homework assignments • Class notes • Class programs • Sample exams • Software instructions • Tutoring information 14
Course Text Book
Course Text Book
Please keep up with the reading!
Please keep up with the reading!
I will post readings both in the primary textbooks and in additional readings
I will post readings both in the primary textbooks and in additional readings
available on-line from the
available on-line from the Bobst SafariBobst Safari library. library.
Required BOOK:
1) Python: Visual QuickStart Guide, 2nd Edition By Toby Donaldson Copyright 2009 o ISBN-10: 0-321-58544-5 o ISBN-13: 978-0-321-58544-8 Optional TextBooks:
1) How to Think Like a Computer Scientist
-Learning with Python 2nd Edition -- free
• by Jeffrey Elkner, Allen B. Downey, and Chris Meyers
• Chapters and examples are posted online:
• http://openbookproject.net/thinkcs/python/engli sh2e/index.html
Software
Software
• For the course, we will be using Python and Idle
• We will discuss installation and how to use software in class
• These programs are free and you can download and use them for your home computer.
•
Install the latest version of Python version 3.1.1
•(Instructions will posted on the course website)
• Python 3.1.1 was released on August 17th, 2009.
1. IDLE, a GUI Program that will make it easy for you to write, edit and debug python programs, is bundled with python (no need to download separately)
Grading
Grading
•
Your grade will be determined as follows:
• Midterm (30%) • Homework (30%) • Final Exam (40%)
homework
homework
• Ten points will be deducted for each class day late, with a possible maximum of 30 points being deducted.
• Home works will not be accepted after the third class following its due date. •For each assignment that you do not hand in within the time limit, your final
grade will be lowered by one letter grade ( i.e., if you are averaging a B+, but you have missed 2 home works, your final grade will be B-).
• Students who spend little time on the homework invariably do poorly on exams and end up with a poor final grade.
• Very Important
• For your own good you must save all programs on back-up (USB or flash
drives). Make and keep copies of all your programs at all times.
• Lost programs or crashed systems do not provide adequate excuses for missing or late homework.
A Word About Cheating
A Word About Cheating
For the purposes of this class, cheating is defined as:
•
Discussing homework concepts is fine, but you must submit your own work.• Copying all or part of another student's homework, project or exam. • Allowing another student to copy all or part of your homework, project,
or exam.
• Please note that If you are caught cheating, you will receive an
immediate FAILURE for the course.
• Copying ideas, text or a line of code (segment) from an outside
resources is NOT allowed “without prior attribution”:
• Make sure to read the CS department statements on Academic Integrity for more details.
If you are caught cheating, you will receive an immediate
FAILURE for the course.
Student Civility
Student Civility
• In an effort to make this class enjoyable for everybody…
• Please be on time to class!
• Please do not talk to your friends and neighbors in class! It disturbs everyone, and makes it hard to concentrate. If you have a question, just ask me!
• Don’t be distracted by passing notes to your neighbors during class. • Don’t use laptops to read emails and browse the web during class • Please turn your pagers and cell-phones off!
• If you are sick and can’t make it to class, make sure to check the
website for class work and also and try to get notes from your classmate
• Class buddy: Let’s do this now: Please turn to your neighbor and
get her/his contact info so you can contact when you need to get notes or other class related info
Getting Help
Getting Help
* Help: Whenever you have a question about the course
material, please feel free to drop by during my office hours or write me an email message. If at any time you feel that you are falling behind or are overwhelmed by the material, let me know: I will be very happy to help you.
• Option 1: Come to my Office Hours
• Office Hours: Mondays: 2 pm - 4 pm in room 321 in
WWH, or at other times by appointment • Location: Room 321 Warren Weaver Hall
• I get bored when nobody visits!
• If you cannot make my office hours, I will be happy to make an appointment with you. Please try to give me advance warning when you need an appointment.
Getting Help
Getting Help
• Help is always available!
• Option 2: See tutors.
• Two lab tutors will devote 10 hours each week to be help you with your homework.
• The tutors will be in room 328 in WWH
• Option 3: Email the class e-tutor, should respond within 24 hours.
• For more information on tutoring, please go to the “Tutoring/Help”
page on the course website:
•
http://www.cs.nyu.edu/courses/spring10/V22.0002-003/tutoring.htm
• Option 4:Other help options:
• CAS Free Peer to Peer tutoring: College Learning Center (located on campus and housed in Weinstein residence hall) offers free peer tutoring for our class. Please note that this effort is not organized by the Computer Science Department and you need to contact the College Learning Center for more information or go to http://www.nyu.edu/cas/clc/.
What Is a Computer?
What Is a Computer?
•
Computer
• Performs computations and makes logical decisions • Millions / billions times faster than human beings
•
Computer programs / software
• Sets of instructions that tells the computer what to do
•
Hardware
24
Computer Organization
Computer Organization
•
Six logical units of computer system
• Input unit
• Mouse, keyboard • Output unit
• Printer, monitor, audio speakers • Memory unit
• Retains input and processed information • Arithmetic and logic unit (ALU)
• Performs calculations • Central processing unit (CPU)
• Supervises operation of other devices • Secondary storage unit
Evolution of Operating Systems
Evolution of Operating Systems
•
Batch processing
• One job (task) at a time
• Operating systems developed
• Programs to make computers more convenient to use • Switch jobs easier
•
Multiprogramming
• “Simultaneous” jobs
Personal Computing, Distributed Computing, and
Personal Computing, Distributed Computing, and
Client/Server Computing
Client/Server Computing
•
Personal computers
• Economical enough for individual
• Popularized by Steve Jobs and Steve Wozniak with the introduction of the Apple in 1977.
• In 1981 IBM introduced the IBM personal computer using “off the shelf” components.
Machine Languages, Assembly Languages, and
Machine Languages, Assembly Languages, and
High-level Languages
High-level Languages
• Three types of programming languages
• Machine languages
• Strings of numbers giving machine specific instructions
• Example:
+1300042774 (these would really be in binary)
+1400593419 +1200274027
• Assembly languages
• English-like abbreviations representing elementary computer
operations (translated via assemblers)
• Example:
LOAD BASEPAY ADD OVERPAY STORE GROSSPAY
Machine Languages, Assembly Languages, and
Machine Languages, Assembly Languages, and
High-level Languages
High-level Languages
• High-level languages
• Instructions closer to everyday English
• English is a natural language. Although high level
programming languages are closer to natural languages, it is difficult to get too close due to the ambiguities in natural languages (a statement in English can mean different things to different people – obviously that is unacceptable for computer programming). However, this is a big research area of computer science.
• Use mathematical notations (translated via compilers)
• Example:
grossPay = basePay + overTimePay
• Interpreter – Executes high level language programs without
compilation.
Some Procedural High-level
Some Procedural High-level
Languages
Languages
•
Other high-level languages
• FORTRAN
• Used for scientific and engineering applications • COBOL
• Used to manipulate large amounts of data • Pascal
The Key Software Trend:
The Key Software Trend:
Object-Oriented programming
Oriented programming
(Examples: Java, C++, and Python)
(Examples: Java, C++, and Python)
•
Objects
• Reusable software components that model items in the real world • Meaningful software units
• Date objects, time objects, paycheck objects, invoice objects, audio objects, video objects, file objects, record objects, etc.
• Any noun can be represented as an object • Very reusable
• More understandable, better organized, and easier to maintain than procedural programming
• Favor modularity
Characteristics of Python
Python is simple Python is object-oriented Python is interpreted Python is robust Python is architecture-neutral Python is portable Python is multithreaded Can be applied in all fields (arts and sciences)
Python was created by Guido Van Rossum in the 1990’s he
32
Basics of a Typical Python Environment
Basics of a Typical Python Environment
1. Edit
• Programmer writes program (called source
code) and stores program on disk (.py file)
2. Run/Execute
• Interpreter translates your source code into
bytecodes into machine language (interpret will generate a file with .pyc) and then execute the instruction producing the result
Another Basic Step for Python
Another Basic Step for Python
Programming
Programming
•
Debugging
• Check program execution and output to ensure program compiles and runs as expected
• If it doesn’t, make corrections in the edit phase and repeat the remaining steps