The >>> is a Python prompt indicating that Python is ready for us to give it a command. These commands are called statements.

Similar documents
Introduction to Computer Programming for Non-Majors CSC 2301, Fall The Department of Computer Science

Introduction to Computer Programming for Non-Majors

Introduction, Programming, Python. Michael Mandel Lecture 1 Methods in Computational Linguistics I The City University of New York, Graduate Center

STEAM Clown & Productions Copyright 2017 STEAM Clown. Page 1

CS 190C: Introduction to Computational Thinking

Starting. Read: Chapter 1, Appendix B from textbook.

Python Programming: An Introduction to Computer Science

CSC 015: FUNDAMENTALS OF COMPUTER SCIENCE I

Lecture 1. basic Python programs, defining functions

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

Intro to Python Programming

Python Programming: An Introduction to Computer Science. John M. Zelle, Ph.D.

Introduction to Computer Programming for Non-Majors

CSI Lab 02. Tuesday, January 21st

CMSC 201 Fall 2018 Lab 04 While Loops

Introduction to Computer Programming for Non-Majors

Python is available at: Why Python is awesome:

CMSC 201 Spring 2017 Lab 01 Hello World

Lecture Writing Programs. Richard E Sarkis CSC 161: The Art of Programming

Introduction to computers and Python. Matthieu Choplin

Programming: detailed instructions which tell the computer hardware what to do aka software Computer Science: the study NOT of computers, but of what

Python Programming: An Introduction to Computer Science

Python for Non-programmers

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

Exploring Python Basics

Exploring Python Basics

CS1 Lecture 3 Jan. 22, 2018

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

Part III Appendices 165

ASCII Art. Introduction: Python

Invent Your Own Computer Games with Python

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration

How to Create a Blog Using Blogger.com

Starting Visual Studio 2005

BCH339N Systems Biology/Bioinformatics Spring 2018 Marcotte A Python programming primer

Pupil Name. Year. Teacher. Target Level. Key Stage 3 Self-Assessment Year 9 Python. Spelling Test No 3. Spelling Test No 2. Spelling Test No 1

Using Accommodate. Information for SAS Students at UofG

CMSC 201 Spring 2018 Lab 01 Hello World

CITS 4406 Problem Solving & Programming

Introduction to Python

Worlframalpha.com Facebook Report

Programming. We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems.

CSCI 121: Anatomy of a Python Script

You Need an Interpreter! Comp Spring /28/08 L10 - An Interpreter

Python Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018

Getting Started with Python

Part 6b: The effect of scale on raster calculations mean local relief and slope

A computer program is a set of instructions that causes a computer to perform some kind of action. It isn t the physical parts of a computer like the

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

CSE 101 Introduction to Computers Development / Tutorial / Lab Environment Setup

Once you define a new command, you can try it out by entering the command in IDLE:

ECS Baruch Lab 3 Spring 2019 Name

How Your First Program Works

Tutorial for loading music files into an Ipad

Writing and Running Programs

Not-So-Mini-Lecture 6. Modules & Scripts

Accuterm 7 Usage Guide

Variables, expressions and statements

Lesson 1 Python: Interactive Fiction

Self-Teach Exercises: Getting Started Turtle Python

What you get When you install Python for your computer, you get a number of features:

Using Accommodate. Information for SAS Students at UofG

CMSC201 Computer Science I for Majors

What Version Number to Install

Introduction to: Computers & Programming: Review prior to 1 st Midterm

Client Based Duplicate Logic

Fundamentals of Programming (Python) Getting Started with Programming

How to build Simbody 2.2 from source on Windows

Calendar: Scheduling, invitations, attachments, and printing

Matlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia

MAILMERGE WORD MESSAGES

Introduction to Programming with JES

UNIT II DATA, EXPRESSIONS, STATEMENTS. Python being a interpreter language has two modes namely: Interactive mode, Script Mode or Normal mode

Intel Edison Tutorial: Introduction to Vim 1

nostarch.com/pfk For bulk orders, please contact us at

Hello, World! An Easy Intro to Python & Programming. Jack Rosenthal

Creating tables of contents

Introduction to Python

CMSC 201 Spring 2019 Lab 06 Lists

Installing Dolphin on Your PC

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

Class 1: Homework. Intro to Computer Science CSCI-UA.0101 New York University Courant Institute of Mathematical Sciences Fall 2017

Lecture. Algorithm Design and Recursion. Richard E Sarkis CSC 161: The Art of Programming

Python Problems MTH 151. Texas A&M University. November 8, 2017

HTML4 TUTORIAL PART 2

PYTHON YEAR 10 RESOURCE. Practical 01: Printing to the Shell KS3. Integrated Development Environment

5 Steps to Processing Marketing Efforts via

UNIT 2B An Introduction to Programming ( for -loops) Principles of Computing, Carnegie Mellon University

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

CS 1110, LAB 1: PYTHON EXPRESSIONS.

L435/L555. Dept. of Linguistics, Indiana University Fall 2016

Laboratory Exercise #0

Math Day 2 Programming: How to make computers do math for you

Creating a Google Scholar Account and using BibTeX to import to Faculty180-1

BNL Worksheets. Introduction

Lesson Share TEACHER'S NOTES LESSON SHARE. ing by Olya Sergeeva. Overview. Preparation. Procedure

Decisions, Decisions. Testing, testing C H A P T E R 7

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

Transcription:

When you start Python, you will see something like: Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. Google Python download Python 3.4 install using IDLE (Python GUI) The is a Python prompt indicating that Python is ready for us to give it a command. These commands are called statements. print("hello, world ) Hello, world print(2+3) 5 print("2+3=", 2+3) 2+3= 5-33- -34-17

Usually we want to execute several statements together that solve a common problem. One way to do this is to use a function. def hello(): print("hello") print("computers are Fun") def hello(): print("hello") print("computers are Fun") The first line tells Python we are defining a new function called hello. The following lines are indented to show that they are part of the hello function. The blank line (hit enter twice) lets Python know the definition is finished. -35- -36-18

def hello(): print("hello") print("computers are Fun") Notice that nothing has happened yet! We ve defined the function, but we haven t told Python to perform the function! A function is invoked by typing its name. hello() Hello Computers are Fun Tips: using Alt+p to get the last command What s the deal with the () s? Commands can have changeable parts called parameters that are placed between the () s. def greet(person): print("hello",person) print ("How are you?") -37- -38-19

greet("terry") Hello Terry How are you? greet("paula") Hello Paula How are you? When we use parameters, we can customize the output of our function. When we exit the Python prompt, the functions we ve defined cease to exist! Programs are usually composed of functions, modules, or scripts that are saved on disk so that they can be used again and again. A module file is a text file created in text editing software (saved as plain text ) that contains function definitions. A programming environment is designed to help programmers write programs and usually includes automatic indenting, highlighting, etc. -39- -40-20

# File: chaos.py # A simple program illustrating chaotic behavior def main(): print("this program illustrates a chaotic function") x = eval(input("enter a number between 0 and 1: ")) for i in range(10): main() We ll use filename.py when we save our work to indicate it s a Python program. In this code we re defining a new function called main. The main() at the end tells Python to run the code. This program illustrates a chaotic function Enter a number between 0 and 1:.5 0.975 0.0950625 0.335499922266 0.869464925259 0.442633109113 0.962165255337 0.141972779362 0.4750843862 0.972578927537 0.104009713267-41- -42-21

Chapter 1: Computers and Programs Computers Computer Science Programming Languages Magic of Python Inside Python # File: chaos.py # A simple program illustrating chaotic behaviour Lines that start with # are called comments Python skips text from # to end of line Intended for human readers and ignored by Python -43- -44-22

def main(): Beginning of the definition of a function called main Since our program has only this one module, it could have been written without the main function. The use of main is customary, however. print("this program illustrates a chaotic function") This line causes Python to print a message introducing the program. -45- -46-23

x = eval(input("enter a number between 0 and 1: ")) x is an example of a variable A variable is used to assign a name to a value so that we can refer to it later. The quoted information is displayed, and the number typed in response is stored in x. for i in range(10): For is a loop construct A loop tells Python to repeat the same thing over and over. In this example, the following code will be repeated 10 times. -47- -48-24

These lines are the body of the loop. The body of the loop is what gets repeated each time through the loop. The body of the loop is identified through indentation. The effect of the loop is the same as repeating this two lines 10 times! for i in range(10): These are equivalent! -49- -50-25

This is called an assignment statement The part on the right-hand side (RHS) of the = is a mathematical expression. * is used to indicate multiplication Once the value on the RHS is computed, it is stored back into (assigned) into x main() This last line tells Python to execute the code in the function main -51- -52-26

Chaos and Computers The chaos.py program: def main(): print("this program illustrates a chaotic function") x = eval(input("enter a number between 0 and 1: ")) for i in range(10): main() For any given input, returns 10 seemingly random numbers between 0 and 1 It appears that the value of x is chaotic Chaos and Computers The function computed by program has the general form kx ( )(1 x) where k is 3.9 This type of function is known as a logistic function. Very small differences in initial value can have large differences in the output. -53- -54-27

Chaos and Computers Input: 0.25 0.73125 0.76644140625 0.698135010439 0.82189581879 0.570894019197 0.955398748364 0.166186721954 0.540417912062 0.9686289303 0.118509010176 Input: 0.26 0.75036 0.73054749456 0.767706625733 0.6954993339 0.825942040734 0.560670965721 0.960644232282 0.147446875935 0.490254549376 0.974629602149 Reminder! Install Python Test Python codes -55- -56-28

Questions Email: mhan@cs.gsu.edu -57-29