CS1022 Computer Programming & Principles

Slides:



Advertisements
Similar presentations
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Advertisements

Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.
CS1022 Computer Programming & Principles
ECS 15 if and random. Topic  Testing user input using if statements  Truth and falsehood in Python  Getting random numbers.
CIS101 Introduction to Computing Week 12. Agenda Your questions Solutions to practice text Final HTML/JavaScript Project Copy and paste assignment JavaScript:
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Introduction to a Programming Environment
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
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.
By Alfredo Alvarez. Agenda: Find out who the instructor is. Talk about goals and why you want to learn python. Discuss the materials and the methodology.
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.
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
CS61A Lecture 2 Functions and Applicative Model of Computation Tom Magrino and Jon Kotker UC Berkeley EECS June 19, 2012.
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
CIS3931 – Intro to JAVA Lecture Note Set 3 19-May-05.
Python.
Eliza the Chatterbox Year 9 Computing HLA
An Introduction to Textual Programming
CS 102 Computers In Context (Multimedia)‏ 01 / 28 / 2009 Instructor: Michael Eckmann.
Topics Introduction Hardware and Software How Computers Store Data
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 9, 2015)
General Programming Introduction to Computing Science and Programming I.
Introduction to Programming Workshop 1 PHYS1101 Discovery Skills in Physics Dr. Nigel Dipper Room 125d
CS1022 Computer Programming & Principles Lecture 1.2 A brief introduction to Python.
CS 108 Computing Fundamentals Notes for Thursday September 10, 2015.
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
CS1022 Computer Programming & Principles Lecture 2.1 Introduction to Algorithms.
CS320n –Visual Programming More LabVIEW Foundations.
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.
You Need an Interpreter!. Closing the GAP Thus far, we’ve been struggling to speak to computers in “their” language, maybe its time we spoke to them in.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015.
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
8 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
Programming Seminar 2009 Night 0. Why we’re holding this seminar You’re probably not a computer science major – Or even anything remotely close (e.g.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Exploring Spyder: An IDE for scientific computing
1. Starting 1 Let’s Learn Saenthong School, January – February 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
COMPUTER PROGRAMMING Year 9 – lesson 1. Objective and Outcome Teaching Objective We are going to look at how to construct a computer program. We will.
CS 201 Lecture 1 (b) Using an IDE Tarik Booker CS 201: Introduction to Programming California State University, Los Angeles.
Chapter 1: Introduction to Computers and Programming
Development Environment
Introduction to Computing Science and Programming I
CS1022 Computer Programming & Principles
GCSE COMPUTER SCIENCE Practical Programming using Python
CS1022 Computer Programming & Principles
Topics Introduction Hardware and Software How Computers Store Data
CS1022 Computer Programming & Principles
Key Ideas from day 1 slides
7 - Programming 7P, Q, R - Testing.
Topic: Functions – Part 2
Variables, Expressions, and IO
Introduction to Programmng in Python
Functions CIS 40 – Introduction to Programming in Python
Introduction to Programming
CS190/295 Programming in Python for Life Sciences: Lecture 1
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Selection CIS 40 – Introduction to Programming in Python
First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
Topics Introduction Hardware and Software How Computers Store Data
COMPUTER PROGRAMMING PYTHON
Notes about Homework #4 Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming:
CISC101 Reminders All assignments are now posted.
Class code for pythonroom.com cchsp2cs
Software Development Techniques
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

CS1022 Computer Programming & Principles Lecture 2.2 A brief introduction to Python (2)

Plan of lecture Intro to Portable Python Integrated development environment (IDE) Edit-run workflow From maths to pseudo-code to Python Codecademy Learning to learn What next? CS1022

Portable Python A pre-configured Python distribution Runs directly on Windows from a USB device Portable, lightweight, hassle-free No need to fiddle with class paths, access rights Large set of libraries bundled together No need to get these separately Drawbacks: Only for Windows CS1022

Portable Python (2) We’ll cover the basics of the IDE Editor and edit-run loop Making sense of mistakes Here’s what you should have: Double-click on “PyScripter-Portable.exe” CS1022

Python interpreter pane Portable Python (3) Here’s what you should see: Files pane Editor pane Python interpreter pane CS1022

Portable Python (4) 2 1 3 Basic edit-run loop: What kinds of problems? Load a file Edit it (editor gives feedback) Run it If there are problems, go to 2 else stop What kinds of problems? Program aborts (does not run) Program runs but does not do what we intended 1 2 3 CS1022

Editing a Python program Let’s edit a new Python program: Highlight the text in 2 Delete all of it Type the following in 2 1 2 3 # absolute value n = -20 if n < 0: abs = -n else: abs = n print(abs) CS1022

Running a Python program To run the program we typed, we can: Type <ctrl-F9> or click on green arrow above pane 2 Program will be run in pane 3 CS1022

Running a Python program (2) If we wanted to try the previous program with different values we would have to edit line 1 Instead, we can provide parameters from keyboard CS1022

Editing a Python program (revisited) Let’s edit our Python program and add the following: import “argv” (functionality) from module “sys” from sys import arg # absolute value n = int(argv[1]) if n < 0: abs = -n else: abs = n print(abs) from sys import arg # absolute value n = -20 if n < 0: abs = -n else: abs = n print(abs) Get first parameter and convert it into an integer CS1022

Parameters from keyboard “argv” allows us to read data from keyboard Data are parameters which we assign to variables It is possible to write programs without parameters We need to initialise variables in the program “initialise” = “give initial values” Every time we want to try different values we need to change these This is tedious... CS1022

Parameters from keyboard (2) We need to tell Python we want to use parameters: CS1022

Parameters from keyboard (2) And provide the actual value(s) CS1022

Defining functions By defining a function we can pass parameters from the interpreter line: def absolute(n): if n < 0: abs = -n else: abs = n return(abs) CS1022

Defining functions In the IDE: CS1022

Formatting your program The editor helps you formatting your program Indentations are important! You still need to confirm what the editor does For instance, when the “if” command is finished CS1022

Program with a “for” loop # sum first n integers n = int(argv[1]) sum = 0 for i in range(1,n): sum = sum + i print(sum) CS1022

Program with a “while” loop Let’s write a program to count down from an input n to 0 We must use a while-loop! while condition: statement CS1022

Codecademy You would have been exposed to it by now... It combines Python with “expected outcomes” Compares your program with an expected solution Errors confusing! Plan of topics Gentle, comprehensive Try both: IDE and Codecademy CS1022

Learning to learn How does one learn to program computers? How should we teach programming? Going over syntax, pragmatics and “tricks of trade” Tedious, very time-consuming Different people have different learning pace/speed Hold back or rush people... Route we took: Expose you to basics of a programming language Support and guide you to learn it in your own pace Use existing on-line resources (we cannot compete with them!) This is an opportunity to “learn to learn” A “soft skill” for life Know what you know; know what you don’t know (AND do something about it!) Help is at hand if you have difficulty (demonstrators, lecturers) CS1022

What next? Work your way through lessons and materials on-line Programming is a skill you get by doing Learn with your mistakes (and successes) The more mistakes, the more you learn! Breaking stuff is fun (no-one is hurt, no damages!) CS1022

Further reading Python’s official Web site https://www.python.org/ Wikipedia’s entry on Python http://en.wikipedia.org/wiki/Python Codecademy on-line Python training http://www.codecademy.com/en/tracks/python Python Humour! (who said we are not fun/funny?) https://www.python.org/doc/humor/ Portable Python http://portablepython.com/ CS1022