Teaching with Python Lukasz Ziarek SUNY Buffalo

Slides:



Advertisements
Similar presentations
Python Mini-Course University of Oklahoma Department of Psychology Day 2 – Lesson 8 Fruitful Functions 05/02/09 Python Mini-Course: Day 2 - Lesson 8 1.
Advertisements

CS 100: Roadmap to Computing Fall 2014 Lecture 0.
 Caesar used to encrypt his messages using a very simple algorithm, which could be easily decrypted if you know the key.  He would take each letter.
Python Magic Select a Lesson: Why Learn to Code? Basic Python Syntax
Program Design and Development
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Admin Office hours 2:45-3:15 today due to department meeting if you change addresses during the semester, please unsubscribe the old one from the.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
index.php Palmyra Area High School 1.
Computer Science 101 Introduction to Programming.
CIS Computer Programming Logic
Introduction to Python
MAT 1000 Mathematics in Today's World Winter 2015.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Munster Programming Training
Section 2.1: Shift Ciphers and Modular Arithmetic The purpose of this section is to learn about modular arithmetic, which is one of the fundamental mathematical.
Systems of Equations as Matrices and Hill Cipher.
Computer Science 101 Introduction to Programming.
Computer Security coursework 2 Dr Alexei Vernitski.
STRINGS CMSC 201 – Lab 3. Overview Objectives for today's lab:  Obtain experience using strings in Python, including looping over characters in strings.
Computer Programming 12 Lesson 3 – Computer Programming Concepts By Dan Lunney.
Encryption on the Internet Eirik Albrigtsen. Encryption & Decryption Text Unreadable Text key + encryption method Unreadable Text Text key + decryption.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
CSC 107 – Programming For Science. The Week’s Goal.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Midterm Review Important control structures Functions Loops Conditionals Important things to review Binary Boolean operators (and, or, not) Libraries (import.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
PYTHON VARIABLES : CHAPTER 2 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.
Data Handling in Algorithms. Activity 1 Starter Task: Quickly complete the sheet 5mins!
Sum of Arithmetic Sequences. Definitions Sequence Series.
ROT13 cipher. The ROT13 cipher is a substitution cipher with a specific key where the letters of the alphabet are offset 13 places. Example: all 'A's.
Introduction to Cryptography Lecture 4. Caesar Cipher Gaius Julius Caesar (100 B.C.- 44 B.C.) General Politician Dictator of Rome Creator of Caesar Cipher.
Announcements No Labs / Recitation this week On Friday we will talk about Project 3 Release late afternoon / evening tomorrow Cryptography.
Information and Computer Security CPIS 312 Lab 1
LAB#3 CLASSICAL ENCRYPTION CPIT 425. This diagram is taken from Dr.Omaima slides.
Midterm preview.
7 - Programming 7J, K, L, M, N, O – Handling Data.
Fundamentals of Programming I Overview of Programming
CSc 110, Autumn 2017 Lecture 15: Strings and Fencepost Loops
Topics Designing a Program Input, Processing, and Output
Encryption.
CMSC201 Computer Science I for Majors Lecture 22 – Binary (and More)
Visual Basic Variables
Vocabulary Big Data - “Big data is a broad term for datasets so large or complex that traditional data processing applications are inadequate.” Moore’s.
Chapter 2 - Introduction to C Programming
Pamela Moore & Zenia Bahorski
Whatcha doin'? Aims: To understand the Caesar Cipher.
Design & Technology Grade 7 Python
Variables, Expressions, and IO
Introduction to Scripting
Introduction to C++ October 2, 2017.
Chapter 2 - Introduction to C Programming
CSc 110, Spring 2017 Lecture 11: while Loops, Fencepost Loops, and Sentinel Loops Adapted from slides by Marty Stepp and Stuart Reges.
Building Java Programs Chapter 2
Five-minute starter task
Language Basics.
Encryption on the Internet
Learning Outcomes –Lesson 4
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Spring 2018 Lecture 14: Booleans and Strings
CSC 221: Introduction to Programming Fall 2018
Forth A stack language.
Fun with Cryptography The Science of Secrecy.
functions: argument, return value
Chapter 2 Programming Basics.
CMPT 120 Lecture 10 – Unit 2 – Cryptography and Encryption –
CMPT 120 Lecture 9 – Unit 2 – Cryptography and Encryption –
COMPUTING.
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Teaching with Python Lukasz Ziarek SUNY Buffalo Oliver Kennedy SUNY Buffalo Sarbani Banerjee Buff State

Benefits of Python Interpreted : Has an interactive mode that students can play with Simple : Low syntactic overhead - students can focus on core concepts Real : Used in many scientific applications Pedigree : Named after ‘Monty Python’

Benefits of Python for teachers Lots of available material : we will provide you with two full curriculums (including projects, assignments, and assessment) Many low cost text books Interfaces with Lego NXT

Learning Objectives Learn core syntax of Python Write a non-trivial program in Python (caesar en-cipher / de-cipher) Ideas how to bring Python into your classroom

Variables Syntax: must start with a letter or “_”, can contain letters, numbers, or “_” You can think of a variable as a box Boxes store things, variables store things (values)

Example >>> cat_in_a_box = True>>> print cat_in_a_boxTrue>>> cat_in_a_hat = 10>>> print cat_in_a_hat10>>> cats = "are great">>> print catsare great Boolean Integer String

Variables Variables store one thing at a time!

Example <- Initial Value >>> cats = "are great">>> print catsare great>>> cats = "and fun">>> print catsand fun <- New Value

But ... Cats are Great AND Fun! >>> cats = "are great and fun">>> print catsare great and fun>>> cats = "are great">>> cats = cats + “ and fun” >>> print catsare great and fun Compute New Value From Old Value

Functions <- Function Definition >>> def loveCats(): We like to re-use our work Functions provide a mechanism to associate a series of Python statements with a name >>> def loveCats(): ... print “I love cats” ... >>> loveCats() I love cats <- Function Definition <- Function Execution <- Function Execution

Functions >>> def loveCats(color): ... print “I love ” +color+ “ cats” ... >>> loveCats(“orange”) I love orange cats >>> loveCats(“tuxedo”) I love tuxedo cats

>>> print x + “ and “ + y Functions >>> def loveCats(color): ... return “I love ” +color+ “ cats” ... >>> x = loveCats(“orange”) >>> print x I love orange cats >>> y = loveCats(“tuxedo”) >>> print y I love tuxedo cats >>> print x + “ and “ + y

<- Condition to check Conditionals Conditionals allow us to execute different statements based on if a condition is true or false >>> x = -1 >>> if x < 10: ... print x ... -1 <- Condition to check <- Code to execute if condition is true

Loops >>> str = “I love cats!” >>> for x in str: Loops allow us to execute a piece of code some number of times AND allow us to “traverse” a structure >>> str = “I love cats!” >>> for x in str: ... print x ... I l o

Encryption These are all the language constructs we need for encryption We need a few auxiliary components: Modular Arithmetic ASCII Encoding

ASCII >>> x = ord(“a”) >>> print x 97 A method to encode characters as numbers (Oliver will present more on this) >>> x = ord(“a”) >>> print x 97 >>> y = chr(97) >>> print y a

Modular Arithmetic >>> 5 % 4 1 Our encryption / decryption algorithm will rely on Modular Arithmetic (tutorial to follow) % is the modulo operator in Python >>> 5 % 4 1

Modular Arithmetic

12 11 1 10 2 9 3 8 4 7 5 6 ??? ??? What’s 4 hours after 3:00? What’s 6 hours after 7:00? 3 + 4 = 7 6 + 7 = 1

(remainder after division) Modulus 6 mod 12 + 7 = 13 mod 12 mod 12 = 1 mod 12 (remainder after division)

Modular Arithmetic Subtraction (6 mod 12) - (9 mod 12) = (9 mod 12) Other Modulii (45 mod 60) + (30 mod 60) = (15 mod 60)

Based on modular arithmetic Cryptography RSA SHA (256, 512, ... ) DES Based on modular arithmetic

(image source: Wikimedia Commons) Cryptography Julius Caesar (image source: Wikimedia Commons)

Cryptography The Caesar Shift Cipher the quick brown fox jumps over the lazy dog WKH TXLFN EURZQ IRA MXPSV RYHU WKH ODCB GRJ The Caesar Shift Cipher

The Caesar Shift Cipher ? ABCDEFGHIJKLMNOPQRSTUVW ABCDEFGHIJKLMNOPQRSTUVWXYZ XYZ (Shift of 3) Encrypt(‘L’, 3) = ‘O’ Encrypt(‘Y’, 3) = ‘B’

ASCII ASCII Code Meaning < 32 Control Codes (Ignore) 32 ‘ ’ (Space) ... Other Printable Characters 126 ‘~’ (Tilde) 127 Delete (Ignore) (95 codes)

Cooperative Task 1 Encrypt(A,i)

Cooperative Task 2 Decrypt(A,i)