Intro to Python & Programming. C-START Python PD Workshop

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

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2

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

Lecture 3. Input, Output and Data Types

My First Python Program

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

Invent Your Own Computer Games with Python

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

Programming Fundamentals and Python

Try typing the following in the Python shell and press return after each calculation. Write the answer the program displays next to the sums below.

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

Only to be used for arranged hours. Order of Operations

Python Programming Exercises 1

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

Conditional Expressions and Decision Statements

Python for Non-programmers

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

Objective- Students will be able to use the Order of Operations to evaluate algebraic expressions. Evaluating Algebraic Expressions

Text Input and Conditionals

Expressions and Variables

Chapter 1 Operations With Numbers

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

>>> * *(25**0.16) *10*(25**0.16)

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

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

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

CSE 374: Programming Concepts and Tools. Eric Mullen Spring 2017 Lecture 4: More Shell Scripts

Introduction to Python

Math 25 and Maple 3 + 4;

Mathematical Data Operators

MIT AITI Python Software Development

Python Unit

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

COMP1730/COMP6730 Programming for Scientists. Data: Values, types and expressions.

Python lab session 1

Programming in C++ PART 2

Python Input, output and variables

CS 115 Data Types and Arithmetic; Testing. Taken from notes by Dr. Neil Moore

Python Input, output and variables. Lecture 22 COMPSCI111/111G SS 2016

ENGG1811 Computing for Engineers Week 1 Introduction to Programming and Python

Recall that strings and tuples are immutable datatypes, while lists are mutable datatypes. What does this mean?

CS 115 Lecture 4. More Python; testing software. Neil Moore

CSI Lab 02. Tuesday, January 21st

Python Games. Session 1 By Declan Fox

CMPT 120 Basics of Python. Summer 2012 Instructor: Hassan Khosravi

CSCI 121: Anatomy of a Python Script

Turn in a printout of your code exercises stapled to your answers to the written exercises at 2:10 PM on Thursday, January 13th.

The C++ Language. Arizona State University 1

1 LOG IN TO APPS.LOSRIOS.EDU AND CLICK ON GOOGLE DRIVE--USE CHROME BROWSER FOR 3 CREATE A GOOGLE DOCS DOCUMENT

Algorithms and Programming I. Lecture#12 Spring 2015

Lecture 4: Basic I/O

Lecture 1. basic Python programs, defining functions

PROBLEM SOLVING 11. July 24, 2012

Learning the Language - V

2/5/2018. Expressions are Used to Perform Calculations. ECE 220: Computer Systems & Programming. Our Class Focuses on Four Types of Operator in C

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

Introduction to Scientific Computing Lecture 1

CS1 Lecture 5 Jan. 25, 2019

Basic Data Types and Operators CS 8: Introduction to Computer Science, Winter 2019 Lecture #2

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

Variables, expressions and statements

Python Class-Lesson1 Instructor: Yao

Python notes from codecademy. Intro: Python can be used to create web apps, games, even a search engine.

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

CSCE 110 Programming I Basics of Python: Variables, Expressions, Input/Output

Compare 9.5. Getting started guide

Topic 3: Fractions. Topic 1 Integers. Topic 2 Decimals. Topic 3 Fractions. Topic 4 Ratios. Topic 5 Percentages. Topic 6 Algebra

Functions and Decomposition

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

ENGR (Socolofsky) Week 02 Python scripts

SAMLab Tip Sheet #1 Translating Mathematical Formulas Into Excel s Language

CS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style

This tutorial will teach you about operators. Operators are symbols that are used to represent an actions used in programming.

MA 1128: Lecture 02 1/22/2018

Module 6. Campaign Layering

CS2304: Python for Java Programmers. CS2304: Sequences and Collections

CS 141, Lecture 3. Please login to the Math/Programming profile, and look for IDLE (3.4 or the unnumbered. <-- fine <-- fine <-- broken

NESTED IF STATEMENTS AND STRING/INTEGER CONVERSION

ENGR 102 Engineering Lab I - Computation

Signed umbers. Sign/Magnitude otation

2.Simplification & Approximation

Python is available at: Why Python is awesome:

Week Two. Arrays, packages, and writing programs

Introduction to Computation for the Humanities and Social Sciences. CS 3 Chris Tanner

Illustrated Guide to the. UTeach Electronic Portfolio

Hello, World and Variables

Divisibility Rules and Their Explanations

MATLAB Demo. Preliminaries and Getting Started with Matlab

CSCE 120: Learning To Code

At full speed with Python

These are notes for the third lecture; if statements and loops.

Fraction Arithmetic. A proper fraction is a fraction with a smaller numerator than denominator.

Connecting to Telegram

Loop structures and booleans

Scripting Languages. Python basics

6.S189 Homework 1. What to turn in. Exercise 1.1 Installing Python. Exercise 1.2 Hello, world!

An Introduction to Python for KS4!

CSCI 141 Computer Programming I. Filip Jagodzinski

ASCII Art. Introduction: Python

Mark Important Points in Margin. Significant Figures. Determine which digits in a number are significant.

Transcription:

Don t just buy a new video game, make one. Don t just download the latest app, help design it. Don t just play on your phone, program it. No one is born a computer scientist, but with a little hard work and some math and science, just about anyone can become one. Barack Obama

Before We Start: A Note on Copy-Paste When small code examples are shown on the slides, it s probably better for you to type in the code examples yourself than try to copy-paste them. You ll learn more by doing so! Larger code examples are provided on the website rather than in the slides. Not to mention, some PDF viewers throw crazy characters at you when you try and copy-paste; Python won t like this!

Review: Variables In math, when we write =, we mean relation: x 3 x + 1 = 0

Review: Variables In math, when we write =, we mean relation: x 3 x + 1 = 0 This is not the same in programming! In most programming languages, including Python, = means assignment. We let the variable on the left take the value on the right. x = 10 y = x + 2 x = 11 print(x, y)

Review: Variables In math, when we write =, we mean relation: x 3 x + 1 = 0 This is not the same in programming! In most programming languages, including Python, = means assignment. We let the variable on the left take the value on the right. x = 10 y = x + 2 x = 11 print(x, y) 11 12

Review: Accepting User Input The input function takes a prompt string, and returns the string the user types. name = input("what is your name? ") print("nice to meet you", name)

Review: Operators Python provides a simple notation to write mathematical statements. + Addition - Subtraction * Multiplicaton ** Exponentation / Division // Integer Division % Modulus (division remainder)

Operators Example in Python REPL >>> (4 + 3) * 6 42 >>> 4 ** 3 64 >>> 33 / 2 16.5 >>> 33 // 2 16 >>> 74 % 8 2 Notice the Notation The >>> symbol is used to indicate lines typed at the interactive interpreter ( Python Shell in IDLE). No need to type >>> yourself.

Comments Comments are a way for programmers to leave notes for others (and sometimes even themselves) in their code. In Python, you can write comments using the # symbol. Anything from # to the end of line will be ignored in Python. # This defines x to the value 10 x = 10 x = x + 1 # add one to x

Comments Comments are a way for programmers to leave notes for others (and sometimes even themselves) in their code. In Python, you can write comments using the # symbol. Anything from # to the end of line will be ignored in Python. # This defines x to the value 10 x = 10 x = x + 1 # add one to x When should I leave comments in my code? Python ignores comments, so you never have to leave comments in your source. However, if you feel that a piece of code needs explanation for other Python programmers to understand it, usually it s a good idea to leave a comment.

The len Function The len function takes a sequence (such as a string) and returns its length. For example: >>> len("jack") 4 >>> len("hello World!") 12

Kattis Kattis is a website that can automatically check your solution to problems. You may optionally use Kattis in this workshop for mini-projects. Kattis could be used in K-12 classrooms. 1 Click Hello World! Kattis problem from workshop website 2 Create an account on Kattis 3 Upload a solution to Hello World! 4 Make sure it got accepted!

Input & Output on Kattis Input on Kattis corresponds to the input function, and output corresponds to the print function. Kattis is pretty lenient on whitespace, so you should be OK adding extra spaces where needed. Kattis considers any prompt you use on the input function to be output, and this will confuse her. So, to get a line of input, use no prompt at all: line = input() Remember input returns a string, so you will need to convert it to an integer if you need it as one. N = int(input())