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

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

Conditionals. C-START Python PD Workshop

Lecture 3 (02/06, 02/08): Condition Statements Decision, Operations & Information Technologies Robert H. Smith School of Business Spring, 2017

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

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

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

Flow Control: Branches and loops

Python for Non-programmers

NESTED IF STATEMENTS AND STRING/INTEGER CONVERSION

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

ENGR 101 Engineering Design Workshop

Unit E Step-by-Step: Programming with Python

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

Python Games. Session 1 By Declan Fox

Key Differences Between Python and Java

Python Unit

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2

from scratch A primer for scientists working with Next-Generation- Sequencing data Chapter 1 Text output and manipulation

Text Input and Conditionals

CSCI 121: Anatomy of a Python Script

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

Hacettepe University Computer Engineering Department. Programming in. BBM103 Introduction to Programming Lab 1 Week 4. Fall 2018

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

Lecture 3. Input, Output and Data Types

Chapter 3 : Informatics Practices. Class XI ( As per CBSE Board) Python Fundamentals. Visit : python.mykvs.in for regular updates

Lecture 4: Basic I/O

CSC Software I: Utilities and Internals. Programming in Python

Lab 4 Fruitful Functions

Introduction to Python (All the Basic Stuff)

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

Python Programming Exercises 1

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

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Python: common syntax

INTERMEDIATE LEVEL PYTHON PROGRAMMING SELECTION AND CONDITIONALS V1.0

Impera've Programming

Real Python: Python 3 Cheat Sheet

CSCE 110 Programming I

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

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

Programming to Python

CMSC 201 Computer Science I for Majors

Python lab session 1

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.

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

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

Lab 2: input(), if else, String Operations, Variable Assignment. Ling 1330/2330: Computational Linguistics Na-Rae Han

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

CS101 Lecture 24: Thinking in Python: Input and Output Variables and Arithmetic. Aaron Stevens 28 March Overview/Questions

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

Fundamentals of Programming. Lecture 1: Introduction + Basic Building Blocks of Programming

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

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

ASCII Art. Introduction: Python

MITOCW watch?v=0jljzrnhwoi

Lecture 3: Recursion; Structural Induction

Introduction to Python Code Quality

Lecture 1. basic Python programs, defining functions

Scripting Languages. Python basics

Python Day 3 11/28/16

MEIN 50010: Python Introduction

Introduction to Programming with Python: overview

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

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

Chapter 2 Writing Simple Programs

A453 Task 1: Analysis: Problem: Solution:

CS177 Recitation. Functions, Booleans, Decision Structures, and Loop Structures

Chapter 2. Designing a Program. Input, Processing, and Output Fall 2016, CSUS. Chapter 2.1

CpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input

C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh

CHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS

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

Conditional Expressions and Decision Statements

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

Basic Concepts. Computer Science. Programming history Algorithms Pseudo code. Computer - Science Andrew Case 2

Oliver BONHAM-CARTER. Fall 2018 Week 2

SAMS Programming - Section C. Lecture 1: Introduction + Basic Building Blocks of Programming

When you open IDLE (Version 3.2.2) for the first time, you're presented with the following window:

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

CS1 Lecture 3 Jan. 18, 2019

ECS Baruch Lab 3 Spring 2019 Name

Expressions and Variables

Writing and Running Programs

Conditionals/Branching

Conditionals and Recursion. Python Part 4

1 Truth. 2 Conditional Statements. Expressions That Can Evaluate to Boolean Values. Williams College Lecture 4 Brent Heeringa, Bill Jannen

Notes on Chapter 1 Variables and String

CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes

Programming: Part I. In this section of notes you will learn about how to write simple programs using JES. Translators

STEAM Clown Productions. Python - Conditional. STEAM Clown & Productions Copyright 2018 STEAM Clown. Last Updated: Thursday, January 24, 2019.


Chapter 1 Operations With Numbers

CSCE 110: Programming I

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

ENGG1811 Computing for Engineers Week 1 Introduction to Programming and Python

Python The way of a program. Srinidhi H Asst Professor Dept of CSE, MSRIT

Step by step set of instructions to accomplish a task or solve a problem

Python Beginners Workbook for Secondary Schools Written by Ali Mulla

PRG PROGRAMMING ESSENTIALS. Lecture 2 Program flow, Conditionals, Loops

Topic 2: Introduction to Programming

Transcription:

An Easy Intro to Python & Programming

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

Your First Python Program Create a file hello.py and type the following contents: print("")

Your First Python Program Create a file hello.py and type the following contents: print("") print is a function, it takes arguments, does things (in this case, print to our console), and returns things

Your First Python Program Create a file hello.py and type the following contents: print("") print is a function, it takes arguments, does things (in this case, print to our console), and returns things The arguments to our print call is just the string "Hello, World".

Your First Python Program Create a file hello.py and type the following contents: print("") print is a function, it takes arguments, does things (in this case, print to our console), and returns things The arguments to our print call is just the string "Hello, World". A string can be written with either single or double quotes, so this program does the same: print('')

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

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)

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

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)

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 (right side of repl.it). 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

Another Kind of Equals == is for equality testing. An expression a == b will be True iff a has the same value as b, False otherwise.

Another Kind of Equals == is for equality testing. An expression a == b will be True iff a has the same value as b, False otherwise. name = input('what is your name? ') print('it is', name == 'Jack', 'that your name is the best.')

Branching if condition: # do something elif other_condition: # do something else else: # do something else

Branching if condition: # do something elif other_condition: # do something else else: # do something else name = input('what is your name? ') if name == 'Jack': print('your name is the best!') elif len(name) == 4: print('your name is 4 letters!') else: print('pleased to meet you', name)

More Comparison Operators < Less than <= Less or equal!= Not equal > Greater than >= Greater or equal is Same instance

More Comparison Operators < Less than <= Less or equal!= Not equal > Greater than >= Greater or equal is Same instance age = int(input('what is your age? ')) if age < 0: print('i don\'t think so') elif age <= 10: print('wow! You\'re young!') elif age!= 16: print('cool cool.') else: print('sweet sixteen.')

Indentation Denotes Scope In Python, indentation not only provides style to help yourself and others read your code, but also provides functionality by denoting the scope of the operation. Consider the following example: # i was defined previously in this program if i > 0: print("i is positive") if i % 2 == 0: print("i is even") print("hello") print("goodbye")

Indentation Denotes Scope In Python, indentation not only provides style to help yourself and others read your code, but also provides functionality by denoting the scope of the operation. Consider the following example: # i was defined previously in this program if i > 0: print("i is positive") if i % 2 == 0: print("i is even") print("hello") print("goodbye") 1 What will be printed if i is 3 2 What will be printed if i is -2 3 What will be printed if i is 4