First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.

Slides:



Advertisements
Similar presentations
Lecture 2 Introduction to C Programming
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction.
Introduction to C Programming
Chapter 2 Basic Elements of Fortan
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
Introduction to C Programming
Basic Elements of C++ Chapter 2.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
Computer Science 101 Introduction to Programming.
CCSA 221 Programming in C CHAPTER 2 SOME FUNDAMENTALS 1 ALHANOUF ALAMR.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
CS 127 Writing Simple Programs.  Stages involved  Analyze the problem  Understand as much as possible what is trying to be solved  Determine Specifications.
Chapter 2 Overview of C Part I J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
Computer Science 101 Introduction to Programming.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.
COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving  Recognizing Patterns  If you can find a pattern in the way you solve.
Getting Started with MATLAB (part2) 1. Basic Data manipulation 2. Basic Data Understanding 1. The Binary System 2. The ASCII Table 3. Creating Good Variables.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
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.
Software Development Environment
Fundamentals of Programming I Overview of Programming
Chapter Topics The Basics of a C++ Program Data Types
Topic: Python’s building blocks -> Variables, Values, and Types
Python: Experiencing IDLE, writing simple programs
Chapter 2 - Introduction to C Programming
Topic: Python’s building blocks -> Variables, Values, and Types
Basic Elements of C++.
The Selection Structure
Chapter 2 - Introduction to C Programming
Basic Elements of C++ Chapter 2.
TRANSLATORS AND IDEs Key Revision Points.
Assembler, Compiler, Interpreter
CS190/295 Programming in Python for Life Sciences: Lecture 1
Chapter 10 Programming Fundamentals with JavaScript
Chapter 2 - Introduction to C Programming
Course websites CS201 page link at my website: Lecture slides
Decision Structures and Indefinite Loops
Introduction to Programming
Elements of a Python Program
More About Functions Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
Variables, Lists, and Objects
Debuggers and Debugging
Simple Graphics Package
Objects (again) Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An Introduction.
More elements of Python programs
Assembler, Compiler, Interpreter
Notes on pyplot Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An Introduction.
Notes about Homework #4 Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming:
CSV files Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An Introduction.
Note on Program Design Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming:
Notes on Homework #6 Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
CISC101 Reminders All assignments are now posted.
Experiment No. (1) - an introduction to MATLAB
12th Computer Science – Unit 5
Introduction to Programming
Computer Programming-1 CSC 111
Numpy, pylab, matplotlib (follow-up)
Introduction to C Programming
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An Introduction to Computer Science, 2nd edition, by John Zelle and copyright notes by Prof. George Heineman of Worcester Polytechnic Institute) CS-1004, A-Term 2014 First Python Program

Problem:– Find area of a disk I.e., area of the part between inner circle and outer circle How to do manually? What value do you use for  ? What if your have a lot of disks? (i.e., with calculator) CS-1004, A-Term 2014 First Python Program

Problem:– Find area of a disk (continued) What about Excel? This is, in fact, a form of programming! Change value of cell  Excel reacts by changing values of all cells depending on that one! A functional “language” CS-1004, A-Term 2014 First Python Program

IDLE — Integrated Development Environment Simple GUI for Python programmers Python “shell” I.e., command interpreter Intelligent file editor Understands Python syntax and formatting Debugger Single-step View values of variables CS-1004, A-Term 2014 First Python Program

More terms — Compiler A computer program that reads another program … … line-by-line, character-by-character … … analyzes it, … … and converts it into internal machine instructions and data CS-1004, A-Term 2014 First Python Program

More terms — Interpreter A computer program that reads one or more lines of another program … … analyzes just those lines … … and executes them in place Much in common with compiler The Python shell is really an interpreter CS-1004, A-Term 2014 First Python Program

Expressions When typed into Python “shell”, evaluated immediately Print Result Much like (the right side of) any scientific or engineering equation Operators +, -, *, /, ** Special operator: // Example: Area of disk Inner radius = 3, outer radius = 5 What value to use for  ? “import” Python’s own value called “pi” CS-1004, A-Term 2014 First Python Program

Questions? CS-1004, A-Term 2014 First Python Program

Variables Definition:– a symbolic name used to refer to a value or to some computational object Starts with a letter or underscore Followed by any sequence of letters, digits, and underscore Case sensitive May not be reserved word — i.e., keyword See Table 2.1 (for all 33 keywords) Subtly different from variables in C, Java, etc. Python variable “refers to” or “points to” a value or object C/Java variable is name of a location where value or object is stored Using a variable Anywhere in an expression or Python statement where the value could have been used instead Examples CS-1004, A-Term 2014 First Python Program

Assignment operator an action variableName = any_valid_Python_expression Makes variableName refer to the value of that expression A specific action that happens at a specific time I.e., when the Python interpreter gets to that particular statement Variable retains what it refers to until changed (by another assignment operator) Like C and Java Unlike Excel Example Inner and outer radii of disk CS-1004, A-Term 2014 First Python Program

Print statement Example print(3 + 2) print(“The sum of 3 and 2 is “, 3 + 2) May be any sequence of values Converted into printable strings “Printed” on output device E.g., The IDLE window … CS-1004, A-Term 2014 First Python Program

Questions? CS-1004, A-Term 2014 First Python Program

Function Definition: A sequence of Python statements that takes zero or more arguments and (optionally) returns a value that can be used in a Python expression Useful when you need to repeat the same computation on different values Example: area of disk Also useful when you want to solve a (sub) problem and then put it out of your mind while working on another problem Especially useful when sharing code With teammates, colleagues, etc. With people you don’t know! CS-1004, A-Term 2014 First Python Program

Calling (i.e., invoking) a function Function name used in Python expression or statement Meaning:– Suspend whatever you were doing Execute the function with the argument values in place of parameters When function “returns”, use its return value at the place where it was called. Examples Area of disk CS-1004, A-Term 2014 First Python Program

Defining functions Indentation matters! return statement Python uses indentation to recognize when still reading part of function vs whatever comes later! return statement Tells Python interpreter to stop interpreting the function and go back to what it was previously doing (Optionally) delivers a value back to “caller” to be used at the point where function was called CS-1004, A-Term 2014 First Python Program

Note “print” and “input” are functions! Almost everything you do in Python will be part of a function Almost every program your submit for homework will consist of one or more functions Functions can (and usually do) call each other! CS-1004, A-Term 2014 First Python Program

Questions? CS-1004, A-Term 2014 First Python Program

This weekend Install Python 3.4 on your own computer or laptop See course website for “cookbook” DO IT TODAY! GET HELP IF YOU NEED IT Homework #1 Available on Course web-site Need WPI password to access Start ASAP Due next Thursday, 6:00 PM Read Chapter 1 Responsible for entire contents of chapter in quizzes CS-1004, A-Term 2014 First Python Program