* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

Programming in Visual Basic
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
CMT Programming Software Applications
Introduction to Computers and Programming Lecture 3: Variables and Input Professor: Evan Korth New York University.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
Introduction to Python
Introduction to C Programming
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
Computer Science 101 Introduction to Programming.
Python.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
CPTR 124 Review for Test 1. Development Tools Editor Similar to a word processor Allows programmer to compose/save/edit source code Compiler/interpreter.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
Computer Science 101 Introduction to Programming.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Software Development. Software Development Loop Design  Programmers need a solid foundation before they start coding anything  Understand the task.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Python Let’s get started!.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
Introduction to Python Lesson 2a Print and Types.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Software Development.
Topics Designing a Program Input, Processing, and Output
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Python Let’s get started!.
Chapter 2 - Introduction to C Programming
Presented By S.Yamuna AP/IT
Variables, Expressions, and IO
Statement atoms The 'atomic' components of a statement are: delimiters (indents, semicolons, etc.); keywords (built into the language); identifiers (names.
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
T. Jumana Abu Shmais – AOU - Riyadh
Chapter 2 - Introduction to C Programming
CISC101 Reminders All assignments are now posted.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Chapter 2 - Introduction to C Programming
Introduction to C Programming
Presentation transcript:

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 1 Class # 2: Introduction to programming using Python Course: Introduction to Computers and Programming using Python V , Section 3, Spring 2010 Professor: Sana Odeh Office hours: Mondays 2:00 pm - 4 pm, room 321 in Courant (this building), or at other times by appointment Course website: 003/index.html 003/index.html

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 2 Introduction What are Programming Languages Introductions to Python Programming basics Introduce the basic structure of Python program How to use python software (Idle) How to design/create/edit/execute/run and debug our Python programs

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 3 What is a program Program is a set of instructions that performs calculations/computation You can also think of programs as software that perform specific tasks allowing you to do the following: Buy products on the web Type reports using MS Word Chat with friends using the iphone Post an album on FaceBook Listen to music using your ipod Play games

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 4 What is a program Programmers like to find recipe (algorithm) for every thing (including intelligence) The focus of programming is to solve problems So we need to develop an algorithm (a solution) Solutions should be clear, efficient, concise (no ambiguity) So, the mathematical algorithm (recipe ) for finding the average for 2 numbers is (a+b)/2 Now, we can write a program to find the average using this algorithm We need to translate this algorithm to a high-level programming language (sentences are written similar to English) average = ( )/ 2 The above statement is similar to how you write a statement in java, C, C++, Ruby, JavaScript, Perl

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 5 So let’s look at how we can write a program A simple in python # my first program in python: let’s print 'hello' on the screen print ("hello") This will print the following to the screen: hello

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 6 Anatomy of a python program Comments Variables Statements Functions Identifiers keywords

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 7 Anatomy of a python program Comments (Good Style): Comments are ignored by the compiler. Makes program easy to read and debug (very important in software development). Provides information about your program and significant segments of code that performs action/computation You should provide comments at the beginning of every program and give the following information: Your name, assignment #, and a brief sentence about the purpose of the program) Here is an example of a first line(s) comment (multiple lines comment) “”” Name: Barack Obama. Homework #1 Program provide an algorithm/solution to fix the US economy “” You should provide one line comments to explain a segment of code (every 5 lines or so whenever you have to perform a specific and important action in you program) # Compute the for average IQ for the last three US presidents avgiq = (obamaiq + bushiq + Clintoniq)/3

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 8 Anatomy of a python program Statements One line of code that performs a specific actions such as assignment avgiq = (obamaiq + bushiq + Clintoniq)/3 Or number = 20 Or name = “Obama”

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 9 Functions Functions are mini programs (small modules) that perform specific actions(s) You can build functions for sorting, searching, computing calculations such as average, and finding whether a number is even or odd 1. Functions can already defined and included with the python software (Built-in ). Many useful functions are available for you to use in your programs such as print() and input() functions. You can simply use in your programs to perform a specific action such as print, perform mathematical operations (square numbers, find sqrt and so on) Example: print(“ I hope you are NOT sleeping”) Example2: To ask user to enter data (numbers, strings), you can use the following function: input(“Mr President, Do you think you are doing a good job so far?”) 2. Functions can be defined by the programmer (User- Defined) will learn how to do this later on They can be called methods in other programming languages

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 10 Variables: labels (a location in memory that points/holds one piece of data (one value ) Locations in memory that holds one piece of data Numbers: (floating-point numbers and whole numbers) -200 (integers- whole numbers without any decimal values) (floating-point numbers ) Text: (String) One or more character name = “Avatar” message = “Hello there”)

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 11 Memory Concepts/Variables (simple definition) Bucket Analogy It is useful to think of a variable for now as a bucket holding one piece of data ( a number or a string). The bucket has a unique name, and can only hold certain kinds of data. price Price is a variable containing the value , and can contain only integers.

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 12 Reserved Words Reserved words or keywords are words that have a specific meaning to the compiler and cannot be used in the program. Reserved words in python: – if – elif – and – Or – for – while

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 13 Python Reserved Words Reserved words in python version 3: Let’s print a list of keywords now using python interactive commands (at the python prompt >>>, you can type commands) >>> import keyword >>> print (keyword.kwlist) 'False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 14 Identifier –Name or labels you can give to names of programs, variables or functions called identifier ( in this case its hello) Series of characters consisting of letters, digits, underscores ( _ ) Must begin with a letter or underscore Does not begin with a digit Should not include spaces Letters are case sensitive (Name is not the same as name) Examples: Welcome1, value, _value, button7 –2num is invalid –Butt on is invalid Pythonis case sensitive (capitalization matters) –a1 and A1 are different

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 15 Programming Errors Syntax Errors –Detected by the compiler Runtime Errors –Causes the program to abort Logic Errors –Produces incorrect result

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 16 Syntax Errors Caused when the compiler cannot recognize a statement. These are violations of the language The compiler normally issues an error message to help the programmer locate and fix it Also called compile errors or compile-time errors. For example, if you forget a quotation mark or a parenthesis needed for print(), you will get a syntax error. print(“hello)

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 17 Run-time Errors Other major kind of error you’ll see Happens when a program is running The compiler cannot identify these errors at compile time. Will talk more about these later i = 1 / 0

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 18 Logic Errors –Produces incorrect result double average = / 2 This program produces in correct answer of 90.0/ = = Answer should be ( )/ /2 = 85.0

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 19 Arithmetic +Addition 2 +2 = 4 *Multiplication 2 * 2 = 4 -Subtractions =0 /Division 3/2 = 1.5 **Power 2**3 = 8 //Division but will truncates decimal values (NO decimal values) 3 // 2 = 1 %MOD/ Moduls: Returns the remainder from a division 3 % 2 = 1

* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed here are copyrighted as well. 20 Simple program to add two numbers # Program will initialize variables and add two numbers # Specify values for num1 and num2 (initialization variables) num1 = 2 num2 = 3 # Adding two numbers and storing result in a variable called "sum" sum = num2 + num1 # Printing numbers and the sum of two numbers print("num1 has a value of ", num1) print("num2 has a value of ", num2) print("The sum of num1 + num2 is ", sum)