The Beauty and Joy of Computing Lecture #18 Besides Blocks I: Intro to Python Amazon Dash is Not an April Fools Joke UC Berkeley EECS Head TA Michael Ball.

Slides:



Advertisements
Similar presentations
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Advertisements

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.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
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.
CSC 160 Computer Programming for Non-Majors Lecture #7: Variables Revisited Prof. Adam M. Wittenstein
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
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.
+ Learn IT 2014: Python Basic programming. + Agenda Python, PyCharm CE Basic programming concepts Creating an executable file using Py2Exe Where to go.
Recitation 1 Programming for Engineers in Python.
The Beauty and Joy of Computing Lecture #25 Summary & Review Facebook’s purchase of Oculus Rift is one indication that this is an incredibly HOT potential.
CS61A Lecture 2 Functions and Applicative Model of Computation Tom Magrino and Jon Kotker UC Berkeley EECS June 19, 2012.
Python Mini-Course University of Oklahoma Department of Psychology Day 1 – Lesson 2 Fundamentals of Programming Languages 4/5/09 Python Mini-Course: Day.
Linux Operations and Administration
CS110/CS119 Introduction to Computing (Java)
UC Berkeley EECS Head TA Michael Ball The Beauty and Joy of Computing Beyond Blocks Python Session 2: Data Structures UC Berkeley EECS TA Peter Sujan (thanks.
School of Computing and Mathematics, University of Huddersfield Computing Science: WEEK 17 Announcement: next few weeks… 9 nd Feb: Comparative Programming.
Introduction to Python Basics of the Language. Install Python Find the most recent distribution for your computer at:
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 9, 2015)
Writing Scala Programs. Command Line There are three common operating systems: Windows (various flavors; I recommend Windows 7) UNIX or Linux (basically.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
CIT 590 Intro to Programming First lecture on Java.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Python – May 11 Briefing Course overview Introduction to the language Lab.
The Beauty and Joy of Computing Lecture #10 Social Implications of Computing Online education now has a player in the open access / free education space,
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
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.
Unit 1 Basic Python programs, functions Special thanks to Roy McElmurry, John Kurkowski, Scott Shawcroft, Ryan Tucker, Paul Beck for their work. Except.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
Jim Havrilla. Invoking Python Just type “python –m script.py [arg]” or “python –c command [arg]” To exit, quit() or Control-D is used To just use the.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
Python Let’s get started!.
Department of Electronic & Electrical Engineering Introduction to C - The Development cycle. Why C? The development cycle. Using Visual Studio ? A simple.
Haskell Basics CSCE 314 Spring CSCE 314 – Programming Studio Using GHC and GHCi Log in to unix.cse.tamu.edu (or some other server) From a shell.
Xi Wang Yang Zhang. 1. Easy to learn 2. Clean and readable codes 3. A lot of useful packages, especially for web scraping and text mining 4. Growing popularity.
UC Berkeley EECS Sr Lecturer SOE Dan Garcia printing-aims-to-prevent-a-piracy-plague/ Quest.
Chris Knight Beginners’ workshop.
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Fundamentals of Programming I Overview of Programming
CST 1101 Problem Solving Using Computers
Computer Science 210 Computer Organization
Introduction to Programming
Introduction to Python
CSC 458– Predictive Analytics I, Fall 2017, Intro. To Python
Variables, Expressions, and IO
basic Python programs, defining functions
Functions CIS 40 – Introduction to Programming in Python
Computer Science 210 Computer Organization
Introduction to Python
basic Python programs, defining functions
An Introduction to Python
Teaching London Computing
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
CSC 458– Predictive Analytics I, Fall 2018, Intro. To Python
CSC1018F: Intermediate Python
Focus of the Course Object-Oriented Software Development
CISC101 Reminders All assignments are now posted.
CSE 303 Concepts and Tools for Software Development
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
L L Line CSE 420 Computer Games Lecture #3 Introduction to Python.
Class code for pythonroom.com cchsp2cs
Functions Taken from notes by Dr. Neil Moore & Dr. Debby Keen
Introduction to Python
Presentation transcript:

The Beauty and Joy of Computing Lecture #18 Besides Blocks I: Intro to Python Amazon Dash is Not an April Fools Joke UC Berkeley EECS Head TA Michael Ball

UC Berkeley “The Beauty and Joy of Computing”: Besides Blocks I (2) Ball Admin Notes  Reminder: Explore Project Part 2 is due Friday  Comments  Artifact + Explanation  Final Projects start next week!  Use Snap! or Python  Individual  3-weeks to work  Demo: (review)) Exporting files from Snap!

UC Berkeley “The Beauty and Joy of Computing”: Besides Blocks I (4) Ball The Goals of BJC  BJC’s goal is not to teach you Snap!  Teach you critical thinking about societal implications of computing  Teach you how to program (Snap! is the best intro language we know) and help you succeed in the future  More importantly: Teach you how to think like a computer scientist in life, called “computational thinking”

UC Berkeley “The Beauty and Joy of Computing”: Besides Blocks I (5) Ball What is Computational Thinking?  Using abstraction (removing detail and generalization with parameters)  It’s understanding the value of a “spec” that specifies a contract  The iterative design cycle: design, prototype, implement, evaluate (loop)  Thinking about how solutions scale, parallelize, generalize, and trying to foresee the unintended consequences!

UC Berkeley “The Beauty and Joy of Computing”: Besides Blocks I (6) Ball Why Learn Python?  You already know it!  Syntax is very similar to Snap!, especially like writing Snap! on paper.  Python (also) runs everywhere  OS X and Windows, and now there are browser apps (Cloud9.io) and even iOS apps  Lots of online support  Plenty of advanced libraries  Everything from graphics processing to AI to games!  Used in industry and academia

UC Berkeley “The Beauty and Joy of Computing”: Besides Blocks I (7) Ball What You’ll Learn  New Syntax  Different way to write programs you already know how to write (in Snap!)  A little bit about the command line  A text-based interface that exposes you to the internals of how a computer works  How to find help online  A little more about Object Oriented Programming  Programming is really not about the language or environment

UC Berkeley “The Beauty and Joy of Computing”: Besides Blocks I (10) Ball Getting Python 3  We’ll be using Python 3 for this class.  It does have some minor changes from Python 2, but you don’t need to worry about what they are.  Download Python 3 from   Run the graphical installer  All official Python documentation is at 

UC Berkeley “The Beauty and Joy of Computing”: Besides Blocks I (11) Ball Intro to the Command Line  “Terminal” on OS X (and Linux) and “Command Prompt” on Windows  a.k.a. “Unix shell” on Mac and Linux  Does the same things as the rest of your computer (browse and edit files, even browse the web!)  OS X:  Open: /Applications/Utilities/Terminal.app  Windows:  Use the search bar for “cmd”

UC Berkeley “The Beauty and Joy of Computing”: Besides Blocks I (12) Ball Python Programs  Python programs are just a text file with Python syntax.  To run a program you type:  python file_name.py  (Sometimes this is python3 )  Aside: a moonscape font indicates a command to run.  Python has two modes – “normal” and “interactive”  Interactive mode happens if you don’t provide a file to run.  After each command Python evaluates your code and returns the response. (Kind of like clicking a block in Snap!)  Use python -i file_name.py  Force a file to be run in interactive mode.

UC Berkeley “The Beauty and Joy of Computing”: Besides Blocks I (14) Ball Text and Numbers  Numbers in Python are called  ints (numbers w/o decimals)  floats (numbers with decimals)  Strings:  Some text in between quotes “” or ‘’ >>> >>> "Hello, " + "world" 'Hello, world'

UC Berkeley “The Beauty and Joy of Computing”: Besides Blocks I (15) Ball Lists  Lists Work in much the same way:  Syntax : [itemA, itemB, itemC] >>> ['B', 'J', 'C'] ['B', 'J', 'C'] >>> len(['B', 'J', 'C']) 3

UC Berkeley “The Beauty and Joy of Computing”: Besides Blocks I (16) Ball BEWARE: Item 0!  However, there is one big difference!  The first item in Python is item 0.  This also applies for strings as well.  Access items using [#] >>> letters = ['B', 'J', 'C'] >>> letters[0] 'B' >>> 'Hello, World!'[7] 'W'

UC Berkeley “The Beauty and Joy of Computing”: Besides Blocks I (17) Ball Variables  No need to “declare” variable in Python,  Just use =  To access a variable, type it’s name >>> course = ['B', 'J', 'C'] >>> school = ’UC Berkeley’ >>> course ['B', 'J', 'C'] >>> school ’UC Berkeley'

UC Berkeley “The Beauty and Joy of Computing”: Besides Blocks I (18) Ball Conditionals >>> if (5 % 2) == 1:... print('This number is odd')... else:... print('This number is even')... This number is odd

UC Berkeley “The Beauty and Joy of Computing”: Besides Blocks I (19) Ball Conditionals  Conditionals Work the same way.  End the condition with :  Parentheses are optional around the condition.  Indent the body 1 “level” (usually 4 spaces  Indentation matters in Python!  To end a condition, just un-indent your code  You can also see that mod in Python is a %  Note that the equals check is ==  Python also supports an if (without the else) just like Snap!

UC Berkeley “The Beauty and Joy of Computing”: Besides Blocks I (20) Ball Loops >>> print('this is a song...') this is a song... >>> while(True):... print('that goes on and on...')... that goes on and on... [omitted] >>> for i in range(1, 11):... print(i)... 1 [omitted 2…10[

UC Berkeley “The Beauty and Joy of Computing”: Besides Blocks I (21) Ball Loops  Loops are similar to conditionals.  Instead of an “until” loop, Python has a “while” loop.  Python is missing the repeat(n) loop and the forever loop, but you can make these with whole and for loops.  Note: range() is a function which is includes the first item, but not the last!  range(1,10) counts from 1 to 9!  You can use this function anywhere in Python.

UC Berkeley “The Beauty and Joy of Computing”: Besides Blocks I (22) Ball Functions >>> def factorial(n):... if n < 1:... return 1... else:... return n * factorial(n - 1)... >>> factorial(4) 24

UC Berkeley “The Beauty and Joy of Computing”: Besides Blocks I (23) Ball Functions  There is no distinction between a command, reporter or predicate.  You can simply use: return None or just return  Python uses the word def  The body of function is indented  All arguments are specified in () and must come at the end of the function name  report  return  Recursion works exactly the same as in Snap!  Call a function like this: name(arg1, arg2..)

UC Berkeley “The Beauty and Joy of Computing”: Besides Blocks I (24) Ball Summary  Lots of little syntax differences!  The Python documentation is your friend  Don’t get too hung up on the differences and don’t get discouraged when you get an error!  There’s so much more to Python in the coming weeks:  Python has thousands of additional, useful built in tools  Python supports HOFs and lambdas  Lots of cool libraries to explore (including turtle graphics)