8 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems

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.
16/13/2015 3:30 AM6/13/2015 3:30 AM6/13/2015 3:30 AMIntroduction to Software Development What is a computer? A computer system contains: Central Processing.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition by Tony Gaddis, Judy Walters,
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.
Why Program? Computer – programmable machine designed to follow instructions Program – instructions in computer memory to make it do something Programmer.
Chapter Introduction to Computers and Programming 1.
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 1.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 1 Computers and Programs.
CISC105 General Computer Science Class 1 – 6/5/2006.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
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.
King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science Department Lecture 1 : Introduction.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
CHAPTER 1 INTRODUCTION 1 st Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
CS 127 Introduction to Computer Science. What is a computer?  “A machine that stores and manipulates information under the control of a changeable program”
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
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.
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.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming
Chapter 1 Introduction 2nd Semester H
Introduction to Programming
Fundamentals of Programming I Overview of Programming
BASIC PROGRAMMING C SCP1103 (02)
Introduction to Computer Systems
A Python Tour: Just a Brief Introduction
Introduction to Programming
Introduction to Programming
Introduction to Programming
Lecture 1: Introduction to JAVA
BASIC PROGRAMMING C SCP1103 (02)
Introduction to Programming
Introduction to Programming
Introduction to Programming
Chapter 1: Introduction to Computers and Programming
CS190/295 Programming in Python for Life Sciences: Lecture 1
What Is a Program? A program is like an algorithm, but describes a process that is ready or can be made ready to run on a real computer Retrieved from:
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction CSC 111.
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Introduction to Programming
Introduction to Programming
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Introduction to Programming
Introduction to Programming
Chapter 1: Programming Basics, Python History and Program Components
Introduction to Programming
Computer Programming-1 CSC 111
Hardware is… Software is…
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

8 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems Spring 2016 Week 1: First Program

Module Information  Time: on Fridays in the spring term.  A-K: lectures to lab sessions to  L-Z: lab sessions to lectures to  Week 9: mock in lab test  Weeks 10 and 11: real in lab test and mock exam 8 January 2016Birkbeck College, U. London2

Assessment Lab attendance (8 classes): 10% In Lab test: 20% Two hour examination in summer 2016: 70% Pass: an average mark of at least 40% The mock examination and a mock in lab test do not contribute to the assessment 8 January 2016Birkbeck College, U. London3

Textbook Essential: Cay Horstmann and Rance Necaise (2014) Python for Everyone, Wiley This module uses the first six chapters of PFE The lab classes are based on exercises in PFE 8 January 2016Birkbeck College, U. London4

Syllabus First program Safe operation of computing equipment Pseudo code and algorithm design Arithmetic Strings Relational operators and Boolean variables if statement Loops Functions Lists Programming exercises 8 January 2016Birkbeck College, U. London5

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. 8 January 2016Birkbeck College, U. London6

Structure of a Computer Central Processing Unit: executes instructions. Primary storage (= main memory): volatile storage of programs and data ready for the CPU Bus: connects the CPU and the primary storage 8 January 2016Birkbeck College, U. London7 CPU primary storage

Peripheral Devices Input devices: mouse, keyboard, microphone Output devices: printer, monitor, speakers Input and Output device: hard drive (non- volatile secondary storage of programs and data) 8 January 2016Birkbeck College, U. London8

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

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. 8 January 2016Birkbeck College, U. London10

Python Developed in the late 80s and early 90s by Guido van Rossum (National Research Institute for Mathematics and Computer Science, The Netherlands) Aim: to produce a language in which small programs can be written quickly The name: from Monty Python’s Flying Circus Python 0.9.0: year 1991 Python 2.0: year 2000 Python 3.0: year January 2016Birkbeck College, U. London11

Advantages of Python Simple syntax (= grammar) Portable without change to Windows, UNIX, Linux and Macintosh operating systems Easy to write programs for complex data Very large standard library 8 January 2016Birkbeck College, U. London12

Zen of Python – first 7 items Beautiful is better than ugly Explicit is better than implicit Simple is better than complex Complex is better than complicated Flat is better than nested Sparse is better than dense Readability counts 8 January 2016Birkbeck College, U. London13

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 8 January 2016Birkbeck College, U. London14

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

Integrated Development Environment  Our IDE for Python is IDLE  IDLE facilities: Create file for program Edit program file Run program  See practical session 8 January 2016Birkbeck College, U. London16

IDLE Editor and Shell 8 January 2016Birkbeck College, U. London17 Left hand: editor, contains program Right hand: shell, receives output when the program is run

My First Program # My first program print("Hello World!") 8 January 2016Birkbeck College, U. London18 When the above program is run in IDLE the string "Hello World!" appears in the shell screen

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() 8 January 2016Birkbeck College, U. London19

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

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 We do not need to know the programming instructions within the function 8 January 2016Birkbeck College, U. London21

Calls to print print("The answer is", 6+7, "!") # three arguments # The output is The answer is 13 ! print("Hello") # one argument print() # no arguments. A blank line is printed print("World") # one argument # The output is Hello World 8 January 2016Birkbeck College, U. London22

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!) 8 January 2016Birkbeck College, U. London23

Indentation # Statements must begin in the same column # The following statements are in error print("Hello") print("World") 8 January 2016Birkbeck College, U. London24

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` 8 January 2016Birkbeck College, U. London25

Run Time Errors  Exception: the syntax is correct but the program stops when the error is encountered, e.g. print(1/0)  An 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!") 8 January 2016Birkbeck College, U. London26

Questions  What does this program print? print("39+3") print(39+3)  What does this program print? print("Hello", "World", "!")  What is the compile time error in this program? print("Hello", "World!) 8 January 2016Birkbeck College, U. London27