Unit 1 Basic Python programs, functions Special thanks to Roy McElmurry, John Kurkowski, Scott Shawcroft, Ryan Tucker, Paul Beck for their work. Except.

Slides:



Advertisements
Similar presentations
Week 1 basic Python programs, defining functions Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where.
Advertisements

Week 5 while loops; logic; random numbers; tuples Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except.
Introduction to Programming with Python Marty Stepp University of Washington Special thanks to Scott Shawcroft, Ryan Tucker,
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
Week 1 basic Python programs, defining functions Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where.
Week 2 expressions, variables, for loops Special thanks to Scott Shawcroft, Ryan Tucker, Paul Beck, Hélène Martin, Kim Todd, John Kurkowski, and Marty.
PYTHON: LESSON 1 Catherine and Annie. WHAT IS PYTHON ANYWAY?  Python is a programming language.  But what’s a programming language?  It’s a language.
Ruby (on Rails) CSE 190M, Spring 2009 Week 1. The Players Kelly "Everyday I'm Hustlin' " Dunn Kim "Mouse" Todd Ryan "Papa T" Tucker.
Python Mini-Course University of Oklahoma Department of Psychology Day 1 – Lesson 2 Fundamentals of Programming Languages 4/5/09 Python Mini-Course: Day.
Introducing Java.
Introduction to Python Dr. Bernard Chen Ph.D. University of Central Arkansas July 9 th 2012
A First Program Using C#
Unit 5 while loops; logic; random numbers; tuples Special thanks to Roy McElmurry, John Kurkowski, Scott Shawcroft, Ryan Tucker, Paul Beck for their work.
Hello World 2 What does all that mean?.
Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.
COMP 171: Principles of Computer Science I John Barr.
August 29, 2005ICP: Chapter 1: Introduction to Python Programming 1 Introduction to Computer Programming Chapter 1: Introduction to Python Programming.
Python From the book “Think Python”
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
Unit 3 parameters and graphics Special thanks to Roy McElmurry, John Kurkowski, Scott Shawcroft, Ryan Tucker, Paul Beck for their work. Except where otherwise.
Unit 2 Expressions and variables; for loops Special thanks to Roy McElmurry, John Kurkowski, Scott Shawcroft, Ryan Tucker, Paul Beck for their work. Except.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Week 1 basic Python programs, defining functions Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where.
Introduction to Python Lesson 1 First Program. Learning Outcomes In this lesson the student will: 1.Learn some important facts about PC’s 2.Learn how.
Week 2 expressions, variables, for loops Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where otherwise.
Week 2 expressions, variables, for loops Special thanks to Scott Shawcroft, Ryan Tucker, Paul Beck, Hélène Martin, Kim Todd, John Kurkowski, and Marty.
8 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
A Python Tour: Just a Brief Introduction "The only way to learn a new programming language is by writing programs in it." -- B. Kernighan and D. Ritchie.
1/10/2008. >>> About Us Paul Beck * Third quarter TA * Computer Engineering * Ryan Tucker * Second quarter TA * Computer.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
8/2/07. >>> About Me Scott Shawcroft * Junior * Computer Engineering * Third Quarter TA * Creative Commons Intern * Small-time Open Source Developer
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
Computer Programming Your First Java Program: HelloWorld.java.
Introduction to Programming
C++ First Steps.
The eclipse IDE IDE = “Integrated Development Environment”
Development Environment
Lecture 8: Python Writing Scripts in GIS
CSc 110, Autumn 2017 Lecture 2: Functions.
A Python Tour: Just a Brief Introduction
CSc 110, Autumn 2017 Lecture 3: Functions.
CSE 190D, Winter 2013 Building Java Programs Chapter 1
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
Introduction to Programming
basic Python programs, defining functions
Introduction to Programming
Adapted from slides by Marty Stepp and Stuart Reges
Assembler, Compiler, Interpreter
Do you know this browser?...
Introduction to Python
basic Python programs, defining functions
Introduction to Algorithm Design
expressions, variables, for loops
expressions, variables, for loops
while loops; logic; random numbers; tuples
Section 1 Introduction To Programming
Introduction to Programming
Introduction to Programming
Assembler, Compiler, Interpreter
CSc 110, Spring 2018 Lecture 2: Functions.
Introduction to Programming with Python
Introduction to Programming
12th Computer Science – Unit 5
Chapter 1: Programming Basics, Python History and Program Components
Input and Output Python3 Beginner #3.
 A function is a named sequence of statement(s) that performs a computation. It contains  line of code(s) that are executed sequentially from top.
Introduction to Computer Science
Introduction to Python
How to Run a Java Program
Presentation transcript:

Unit 1 Basic Python programs, functions Special thanks to Roy McElmurry, John Kurkowski, Scott Shawcroft, Ryan Tucker, Paul Beck for their work. Except where otherwise noted, this work is licensed under:

2 Python! Created in 1991 by Guido van Rossum (now at Google)  Named for Monty Python Useful as a scripting language  script: A small program meant for one-time use  Targeted towards small to medium sized projects Used by:  Google, Yahoo!, Youtube  Many Linux distributions  Games and apps (e.g. Eve Online)

3 Installing Python Windows: Download Python from Install Python. Run Idle from the Start Menu. Mac OS X: Python is already installed. Open a terminal and run python or run Idle from Finder. Linux: Chances are you already have Python installed. To check, run python from the terminal. If not, install from your distribution's package system. Note: For step by step installation instructions, see the course web site.

4 Interpreted Languages interpreted  Not compiled like Java  Code is written and then directly executed by an interpreter  Type commands into interpreter and see immediate results Computer Runtime Environment CompilerCode Java: ComputerInterpreterCode Python:

5 The Python Interpreter Allows you to type commands one-at-a-time and see results A great way to explore Python's syntax  Repeat previous command: Alt+P

6 Our First Python Program Python does not have a main method like Java  The program's main code is just written directly in the file Python statements do not end with semicolons hello.py 1print("Hello, world!")

7 The print Statement print(" text ") print() (a blank line)  Escape sequences such as \" are the same as in Java  Strings can also start/end with ' swallows.py print("Hello, world!") print() print("Suppose two swallows \"carry\" it together.") print('African or "European" swallows?')

8 Comments Syntax: # comment text (one line) swallows2.py # Suzy Student, CSE 142, Fall 2097 # This program prints important messages. print("Hello, world!") print() # blank line print("Suppose two swallows \"carry\" it together.") print('African or "European" swallows?')

9 Functions Function: Equivalent to a static method in Java. Syntax: def name (): statement... statement  Must be declared above the 'main' code  Statements inside the function must be indented hello2.py # Prints a helpful message. def hello(): print("Hello, world!") # main (calls hello twice) hello()

10 Whitespace Significance Python uses indentation to indicate blocks, instead of {}  Makes the code simpler and more readable  In Java, indenting is optional. In Python, you must indent. hello3.py # Prints a helpful message. def hello(): print("Hello, world!") print("How are you?") # main (calls hello twice) hello()

11 Exercise Rewrite the Figures lecture program in Python. Its output: ______ / \ \ / \______/ \ / \______/ ______ / \ | STOP | \ / \______/ ______ / \

12 Exercise Solution def egg(): top() bottom() print() def cup(): bottom() line() print() def stop(): top() print("| STOP |") bottom() print() def hat(): top() line() print() def top(): print(" ______") print(" / \\") def bottom(): print("\\ /") print(" \\______/") def line(): print(" ") # main egg() cup() stop() hat()