Introduction to Programming

Slides:



Advertisements
Similar presentations
11 January 2013Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Advertisements

EC-111 Algorithms & Computing Lecture #1 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
Chapter 1 These slides for CSE 110 Sections are based in part on the textbook-authors’ slides, which are copyright by the authors. The authors state that.
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
Computer Programming-1 CSC 111 Chapter 1 : Introduction.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 1 Computers and Programs.
Introduction to Computational Linguistics Programming I.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Chapter One: Introduction.
Week 1 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
August 29, 2005ICP: Chapter 1: Introduction to Python Programming 1 Introduction to Computer Programming Chapter 1: Introduction to Python Programming.
Python From the book “Think Python”
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 1 February 8, 2005.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
Unit 1 Basic Python programs, functions Special thanks to Roy McElmurry, John Kurkowski, Scott Shawcroft, Ryan Tucker, Paul Beck for their work. Except.
CS 127 Introduction to Computer Science. What is a computer?  “A machine that stores and manipulates information under the control of a changeable program”
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Chapter 1 Introduction. Chapter Goals To understand the activity of programming To learn about the architecture of computers To learn about machine code.
Chapter 1 09/04/13. Change Your Password  The command is: passwd In the lab first do : ssh -Y onyx  You will have to see me to change it, if you forget.
8 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
Introduction to Programming Python Lab 1: My First Program 8 January PythonLab1 lecture slides.ppt Ping Brennan
A Python Tour: Just a Brief Introduction "The only way to learn a new programming language is by writing programs in it." -- B. Kernighan and D. Ritchie.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
Introduction to Computer Programming using Fortran 77.
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
And now for something completely different…
Introduction to Programming
Fundamentals of Programming I Overview of Programming
Department of Computer Science,
A Python Tour: Just a Brief Introduction
Introduction to Programming
Python: Experiencing IDLE, writing simple programs
Introduction to Programming
Topics Introduction Hardware and Software How Computers Store Data
Introduction to Programming
Lecture 1: Introduction to JAVA
Lesson 1 An Introduction
Introduction to Programming
basic Python programs, defining functions
Java programming lecture one
Introduction to Programming
Introduction to Programming
Unit# 8: Introduction to Computer Programming
CS190/295 Programming in Python for Life Sciences: Lecture 1
Introduction to Python
basic Python programs, defining functions
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction CSC 111.
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Computer Programming
Introduction to Programming
Introduction to Programming
12th Computer Science – Unit 5
Chapter 1: Programming Basics, Python History and Program Components
Introduction to Programming
Introduction to Programming
Introduction to Programming
Computer Programming-1 CSC 111
Hardware is… Software is…
Chapter 1: Introduction to Computers and Programming
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Introduction to Programming Department of Computer Science and Information Systems Tingting Han (afternoon), Steve Maybank (evening) tingting@dcs.bbk.ac.uk sjmaybank@dcs.bbk.ac.uk Autumn 2018 Week 1: First Program Birkbeck College, U. London

Birkbeck College, U. London Module Information Full time students: 14.00-17.00 on Tuesdays in the autumn term. 14.00 – 15.20 Lectures: GOR B04 15.40 – 17.00 Lab: MAL 109 Part time students: 18.00-21.00 on Tuesdays in the autumn term. First half: lecture, second half: lab class Birkbeck College, U. London

Birkbeck College, U. London Assessment Lab attendance (9 classes): 10% In lab test (Week 11): 20% Two hour written examination in summer 2019: 70% Pass: an overall mark of at least 40% Example: 6 lab classes, 45% in lab test, 38% examination. Overall mark: ((6/9)*100)*(1/10)+45*(2/10)+38*(7/10) = 42.27 Birkbeck College, U. London

Tests and Examinations Week 10 – first half: mock examination Week 10 – second half: mock in laboratory test Week 11 – second half: in laboratory test The mock examination and the mock in lab test are for practice only. They will not be marked. Birkbeck College, U. London

Birkbeck College, U. London Teaching Materials Slides, lab worksheets, example programs, etc. will be posted on Prof. Maybank’s ITP web page http://www.dcs.bbk.ac.uk/~sjmaybank/ITP%20autumn%202017/introduction%20to%20Programming.html The timetable and syllabus will be posted on Moodle and on Prof. Maybank’s ITP web page Moodle will be used for messages to the class Birkbeck College, U. London

Birkbeck College, U. London Textbook Essential: Cay Horstmann and Rance Necaise (2014) Python for Everyone, Wiley Teaching is based on the first six chapters of PFE The lab classes are based on exercises in PFE Birkbeck College, U. London

Birkbeck College, U. London Syllabus First program: print("Hello World") Safe operation of equipment: avoid RSI (Repetitive Strain Injury) Variables: q = 2 Pseudo code and algorithm design Arithmetic and Input: (1+4)/5; input("Type a number") Strings and Output: print("Hello World"); print(q) Relational operators and Boolean variables: 2 < 5 if statement: if (2 < 5) : Loops: while (q < 3) : Functions: q = max(2, 3) - encapsulate Lists: [4, -5, 2] Birkbeck College, U. London

Birkbeck College, U. London This Lecture Based on Ch. 1 of PFE Aim 1: provide background information on computing Aim 2: provide enough information to write a first Python program. Birkbeck College, U. London

Structure of a Computer primary storage CPU Central Processing Unit: executes in sequence small fragments of code known as instructions. Primary storage (= main memory): stores programs and data required by the CPU Bus: connects the CPU and the primary storage Birkbeck College, U. London

Birkbeck College, U. London Peripheral Devices Input devices: mouse, keyboard, microphone, touchpad Output devices: printer, monitor, speakers Input and Output device: hard drive – secondary storage large capacity storage of programs and data Birkbeck College, U. London

Birkbeck College, U. London Problem The CPU of a computer can only carry out a few simple instructions known as machine code It is time consuming and error prone to write programs using these simple instructions Birkbeck College, U. London

Birkbeck College, U. London Solution Write programs in a high level language which is easier to understand than machine code. Use another program to convert high level programs into lists of machine code instructions for the CPU. Python is a high level programming language. Birkbeck College, U. London

Birkbeck College, U. London Python Developed in the late 80s and early 90s by Guido van Rossum National Research Institute for Mathematics and Computer Science (CWI), The Netherlands Google (2005-2012) Dropbox (2013-) Aim: to produce a language in which small programs can be written quickly Over six years ago, in December 1989, I was looking for a "hobby" programming project that would keep me occupied during the week around Christmas. My office ... would be closed, but I had a home computer, and not much else on my hands. I decided to write an interpreter for the new scripting language I had been thinking about lately: a descendant of ABC that would appeal to Unix/C hackers. I chose Python as a working title for the project, being in a slightly irreverent mood (and a big fan of Monty Python's Flying Circus). When he began implementing Python, Guido van Rossum was also reading the published scripts from “Monty Python's Flying Circus”, a BBC comedy series from the 1970s. Van Rossum thought he needed a name that was short, unique, and slightly mysterious, so he decided to call the language Python. He was employed by Google from 2005 until December 7th 2012, where he spent half his time developing the Python language. In January 2013, van Rossum started working for Dropbox.[3] Birkbeck College, U. London

Birkbeck College, U. London Python The name: from Monty Python’s Flying Circus Python 0.9.0: year 1991 Python 2.0: year 2000 Python 3.0: year 2008 Now: Python 3.7.0 June, 2018 a BBC comedy series from the 1970s Birkbeck College, U. London

Birkbeck College, U. London Advantages of Python Simple syntax (= grammar) Portable without change to different operating systems Windows, UNIX, Linux and Mac Easy to write programs for complex data Very large standard library text processing, data compression, file formats, mathematical functions, … Birkbeck College, U. London

Birkbeck College, U. London Python Interpreter The interpreter consists of a compiler and a virtual machine The compiler converts Python instructions to simpler instructions known as byte code The virtual machine is a software version of a CPU. It runs the byte code Birkbeck College, U. London

From Source Code to Running Program Birkbeck College, U. London

Birkbeck College, U. London An Analogy High level program CPU converter machine code Python program Virtual machine compiler byte code Python Interpreter Birkbeck College, U. London

Birkbeck College, U. London Portability The virtual machine is not portable Once the virtual machine is installed, it can run the byte code from any Python program Birkbeck College, U. London

Integrated Development Environment (IDE) Our IDE for Python is IDLE IDLE facilities: Create file for program Edit program file Run program See laboratory session Birkbeck College, U. London

IDLE Editor and Shell Editor Shell contains program receives output when the program is run Left hand: editor, contains program Right hand: shell, receives output when the program is run

My First Program When the above program is run in IDLE the string "Hello World!" appears in the shell screen

Birkbeck College, U. London Commentary # My first program is a comment. It is ignored by the interpreter print("Hello World!") is a statement print is the name of a function print("Hello World!") is a function call The string "Hello World!” is an argument for the function print() Birkbeck College, U. London

Birkbeck College, U. London Colour Coding in IDLE Red for comments: # My first program Purple for functions: print(…) Green for data: "Hello World!" Blue for output: "Hello World!" Birkbeck College, U. London

Birkbeck College, U. London More About Functions A function is a collection of programming instructions that carry out a particular task Example: print("Hello World!") We know the name of the function, the data supplied to the function and the data obtained from the function (in this example as printed output) The programming instructions within the function print are hidden Birkbeck College, U. London

Birkbeck College, U. London Calls to print print("The answer is", 6+7, "!") # three arguments # The output is The answer is 13 ! # , will add a space print("Hello") # one argument print() # no arguments. A blank line is printed print("World") # one argument Hello World Birkbeck College, U. London

Birkbeck College, U. London Errors Python is case sensitive: Print("Hello World!") # error if print is intended PRINT("Hello World!") # error if print is intended Syntax errors: print(Hello World!) print("Hello World!) Birkbeck College, U. London

Birkbeck College, U. London Indentation # Statements must begin in the same column # The following statements are in error print("Hello") print("World") In Python, it is required for indicating what block of code a statement belongs to by indentation. Birkbeck College, U. London

Birkbeck College, U. London Compile Time Error An error in the syntax (grammar of Python) is detected by the compiler, e.g. print(Hello World!) An error message is produced, in this case SyntaxError: invalid syntax The error must be corrected `by hand` Birkbeck College, U. London

Birkbeck College, U. London Run Time Errors Run time exception: the program is compiled but the run time process stops when the error is encountered, e.g. print(1/0) A run time exception produces an error message, in this case ZeroDivisionError: int division or modulo by zero Run time error (but not an exception): the program runs but does not produce the desired result, e.g. print("Helo World!") Birkbeck College, U. London

Birkbeck College, U. London Questions What does this program print? print("39+3") print(39+3) print("Hello", "World", "!") What is the error in this program? print("Hello", "World!) Is it a compile time error or run time exception or run time error? Birkbeck College, U. London