Professor Hugh C. Lauer CS-1004 Introduction to Programming for Non-Majors

Similar documents
Professor Hugh C. Lauer CS-1004 Introduction to Programming for Non-Majors

Consolidation and Review

SAMS Programming A/B. Lecture #1 Introductions July 3, Mark Stehlik

Programming in Java Prof. Debasis Samanta Department of Computer Science Engineering Indian Institute of Technology, Kharagpur

Civil Engineering Computation

Lab # 2. For today s lab:

Lesson 1A - First Java Program HELLO WORLD With DEBUGGING examples. By John B. Owen All rights reserved 2011, revised 2015

Chris Simpkins (Georgia Tech) CS 2316 Data Manipulation for Engineers Python Overview 1 / 9

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

CS 190C: Introduction to Computational Thinking

Scientific Computing: Lecture 1

Project 0: Linux & Virtual Machine Dabbling

Introduction to programming with Python

Algorithms and Programming I. Lecture#12 Spring 2015

Chapter 1: A First Program Using C#

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Week - 01 Lecture - 04 Downloading and installing Python

Laboratory Assignment #3 Eclipse CDT

CSC 015: FUNDAMENTALS OF COMPUTER SCIENCE I

Setting up Python 3.5, numpy, and matplotlib on your Macintosh or Linux computer

Programs as Models. Procedural Paradigm. Class Methods. CS256 Computer Science I Kevin Sahr, PhD. Lecture 11: Objects

CS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017

CS 323 Lecture 1. Design and Analysis of Algorithms. Hoeteck Wee

T H E I N T E R A C T I V E S H E L L

Programming In Java Prof. Debasis Samanta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s

CMPS 12A Introduction to Programming Lab Assignment 7

CSI Lab 02. Tuesday, January 21st

Setting up Python 3.5 and numpy and matplotlib on your own Windows PC or laptop

Eclipse Environment Setup

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Nesting. Abstraction & Nesting. Example. if x is less than y output x is smaller else output y is smaller. CS256 Computer Science I Kevin Sahr, PhD

Introduction to Data Structures

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu)

TTh 9.25 AM AM Strain 322

Introduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas

Programming for Engineers in Python

Processor. Lecture #2 Number Rep & Intro to C classic components of all computers Control Datapath Memory Input Output

Jython. secondary. memory

Cost of Your Programs

A Linux Virtual Machine for CS-2011 Projects

Objectives. Structure. Munster Programming Training

Week One: Introduction A SHORT INTRODUCTION TO HARDWARE, SOFTWARE, AND ALGORITHM DEVELOPMENT

CHAPTER 6 ACTIONS, METHODS, REFACTORING

Computer Hardware. Java Software Solutions Lewis & Loftus. Key Hardware Components 12/17/2013

More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4

last time in cs recitations. computer commands. today s topics.

Structured Programming

CS1 Lecture 5 Jan. 25, 2019

Setting up Python 3.4 and numpy and matplotlib on your own Windows PC or laptop

CS 240 Fall Mike Lam, Professor. Just-for-fun survey:

CS 177 Recitation. Week 1 Intro to Java

Sixth lecture; classes, objects, reference operator.

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

Manju Muralidharan Priya. CS4PM Web Aesthetics and Development WEEK 11

Assignment 3, Due October 4

Unit E Step-by-Step: Programming with Python

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Welcome to Solving Problems with Computers I

Fundamental of Programming (C)

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

Introduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Computer Programming-1 CSC 111. Chapter 1 : Introduction

Our Strategy for Learning Fortran 90

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Computer Components. Software{ User Programs. Operating System. Hardware

CS 360: Programming Languages Lecture 10: Introduction to Haskell

Programming for Engineers in Python. Recitation 1

Course Outline. Introduction to java

CS106 Lab 1: Getting started with Python, Linux, and Canopy. A. Using the interpreter as a fancy calculator

Review: Classes and Object Instances. Review: Creating an Object. Using Multiple Objects. DrawingGizmo pencil; pencil = new DrawingGizmo();

CS 240 Fall 2015 Section 004. Alvin Chao, Professor

(Ca...

CMSC201 Computer Science I for Majors

Solving Problems Flow Control in C++ CS 16: Solving Problems with Computers I Lecture #3

Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6

CS Exam 1 Review Suggestions

Outline. Announcements. Homework 2. Boolean expressions 10/12/2007. Announcements Homework 2 questions. Boolean expression

CGS 3066: Spring 2015 JavaScript Reference

CompSci 125 Lecture 02

Expressions and Variables

Comp 151. Control structures.

CS1 Lecture 3 Jan. 18, 2019

Module 01: Introduction to Programming in Python

S206E Lecture 19, 5/24/2016, Python an overview

CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2

CSc Introduction to Computing

The Eclipse Parallel Tools Platform

Programming for Engineers in Python. Autumn

Your first C and C++ programs

CS1 Lecture 3 Jan. 22, 2018

Programming for Engineers in Python

This is the basis for the programming concept called a loop statement

Lecture 1. basic Python programs, defining functions

Languages. Solve problems using a computer, give the computer instructions. Remember our diaper-changing exercise?

Functions Structure and Parameters behind the scenes with diagrams!

Introduction to C++ General Rules, Conventions and Styles CS 16: Solving Problems with Computers I Lecture #2

Lecture 1. A. Sahu and S. V. Rao. Indian Institute of Technology Guwahati

Transcription:

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, 2 nd edition, by John Zelle and copyright notes by Prof. George Heineman of ) 1

Problem: Find area of a disk I.e., area of the part between inner circle and outer circle How to do manually? (i.e., with calculator) What value do you use for? What if your have a lot of disks? 2

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 3

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 4

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 5

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 6

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 7

Questions? 8

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 9

Assignment operator 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 10

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 11

Questions? 12

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! 13

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 14

Defining functions Indentation matters! 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 15

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! 16

Questions? 17

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 18