Introduction to programming (LT2111) Lecture 1: Introduction

Similar documents
Introduction to programming Lecture 4: processing les and counting words

Fundamentals of Programming. Lecture 1: Introduction + Basic Building Blocks of Programming

Practice 1 1: Instance or Entity

COMP 102: Computers and Computing

CS1110 Lab 1 (Jan 27-28, 2015)

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

The diagram below is only partially complete. Use the terms in the word list to complete the empty boxes. Make dinner

Department of Electrical Engineering and Computer Sciences Spring 2001 Instructor: Dan Garcia CS 3 Midterm #2. Personal Information

CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) First Name: Last Name: NetID:

Selection statements. CSE 1310 Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington

SAMS Programming - Section C. Lecture 1: Introduction + Basic Building Blocks of Programming

Introduction to computers and Python. Matthieu Choplin

Introduction to the course and basic programming concepts

PROGRAMMING FUNDAMENTALS

LABORATORY OF DATA SCIENCE. Python & Spyder- recap. Data Science & Business Informatics Degree

EPV TECHNOLOGIES NEWSLETTER April 2018

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu)

Introduction Jan. 22, Ch 1

Faculty of Mechanical Engineering UTM

Lecture 1. Course Overview, Python Basics

CS101 Lecture 24: Thinking in Python: Input and Output Variables and Arithmetic. Aaron Stevens 28 March Overview/Questions

Assignment 3, Due October 4

CSCI 121: Anatomy of a Python Script

CS240: Programming in C

C++ Programming Language Lecture 2 Problem Analysis and Solution Representation

Foreword. Agenda 22/09/2009 INTRODUCTION TO VBA PROGRAMMING. Foundations. Tools

Think Java: How to Think Like a Computer Scientist, written by

SAMS Programming A/B. Lecture #1 Introductions July 3, Mark Stehlik

The cuisine package. Ben Cohen. 2000/08/01, v0.5

Testing and Debugging

Outline. Program development cycle. Algorithms development and representation. Examples.

Introduction to Python (All the Basic Stuff)

CSC 015: FUNDAMENTALS OF COMPUTER SCIENCE I

Numerical Methods in Physics. Lecture 1 Intro & IEEE Variable Types and Arithmetic

Sum this up for me. Let s write a method to calculate the sum from 1 to some n. Gauss also has a way of solving this. Which one is more efficient?

CS Compiler Construction West Virginia fall semester 2014 August 18, 2014 syllabus 1.0

CSI Lab 02. Tuesday, January 21st

2.9 Modularization. Department of CSE,Coimbatore

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

Advanced Computer Networks. Rab Nawaz Jadoon DCS. Assistant Professor COMSATS University, Lahore Pakistan. Department of Computer Science

Week - 01 Lecture - 04 Downloading and installing Python

Classical Internet Applications

Al al-bayt University Prince Hussein Bin Abdullah College for Information Technology Computer Science Department

Act like a code monkey Coding Basics

Lecture 1. Course Overview, Python Basics

(Refer Slide Time 04:53)

Csci 132 Spring 13. Assignment 2 Due: Tuesday, March 5 (by 11:59PM)

Algorithms II Can t stop, won t stop

Computer Science 217

Hello, World! An Easy Intro to Python & Programming. Jack Rosenthal

Unit 7: Algorithms and Python CS 101, Fall 2018

CSCE 110 Programming I

CPSC 121: Models of Computation. Module 5: Predicate Logic

CS 6371: Advanced Programming Languages

EECS 282 Information Systems Design and Programming. Atul Prakash Professor, Computer Science and Engineering University of Michigan

Languages and Compilers

Computers and programming languages introduction

UNIT 5B Binary Search

EECS 282 Information Systems Design and Programming. Atul Prakash Professor, Computer Science and Engineering University of Michigan

Lab 4 Fruitful Functions

NLP Final Project Fall 2015, Due Friday, December 18

Databases 2 (VU) ( )

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

BCH339N Systems Biology/Bioinformatics Spring 2018 Marcotte A Python programming primer

Algorithms and Programming I. Lecture#12 Spring 2015

Computer Science AP 2017 Summer Assignment Mrs. McFarland

Data Representation. Interpreting bits to give them meaning. Part 1: Numbers, Bases, and Binary

CS 4800: Algorithms & Data. Lecture 1 January 10, 2017

15-110: Principles of Computing, Spring 2018

Linear Classification and Perceptron

Admin. How's the project coming? After these slides, read chapter 13 in your book. Quizzes will return

Top Down Breaking a Problem Down

Structure and Interpretation of Computer Programs Spring 2017 Mock Midterm 1

PROGRAMMING FUNDAMENTALS

Course Overview, Python Basics

EECS 470 Lab 5. Linux Shell Scripting. Friday, 1 st February, 2018

Oliver BONHAM-CARTER. Fall 2018 Week 2

T H E I N T E R A C T I V E S H E L L

Programming for Engineers in Python

Types and Static Type Checking (Introducing Micro-Haskell)

Types and Static Type Checking (Introducing Micro-Haskell)

1 Check it out! : Fundamentals of Programming and Computer Science, Fall Homework 3 Programming: Image Processing

Extended Introduction to Computer Science CS1001.py Lecture 10, part A: Interim Summary; Testing; Coding Style

CMSC 201 Computer Science I for Majors

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0. L J Howell UX Software Ver. 1.0

Introduction to programming Lecture 5

Compilers for Modern Architectures Course Syllabus, Spring 2015

Algorithms. Chapter 8. Objectives After studying this chapter, students should be able to:

ECS 15: Introduction to Computers Midterm November 2 nd, 2011

PROGRAMMING FUNDAMENTALS

Elementary Computing CSC 100. M. Cheng, Computer Science

Bindel, Fall 2016 Matrix Computations (CS 6210) Notes for

CSE 115. Introduction to Computer Science I

COMP-202 Unit 0: Course Details

CSE 115. Introduction to Computer Science I

Computer Science 217

Introduction to Functional Programming. Slides by Koen Claessen and Emil Axelsson

CSC148, Lab #4. General rules. Overview. Tracing recursion. Greatest Common Denominator GCD

When Brunel s ship the SS Great Britain was launched into the River Thames, it made such a splash that several spectators on the opposite bank were

CSE : Python Programming

Transcription:

Introduction to programming (LT2111) Lecture 1: Introduction Richard Johansson September 2, 2014

Introduction & Administration The main goal of the course is that you will learn how to program using the programming language Python. Teachers: Richard Johansson Malin Ahlberg Ildikó Pilán Course coordinator Course assistant Course assistant richard.johansson@gu.se malin.ahlberg@gu.se ildiko.pilan@gu.se

Schedule Course homepage: http://spraakbanken.gu.se/personal/richard/itp2014 We will meet on Tuesdays and Fridays: lecture assignment supervision 45 min + 15 min break + 45 min

Course literature Main course book: Python for software design, how to think like a computer scientist, Allen B. Downey Natural Language Processing with Python, Steven Bird et al. (we will only use the rst chapters, but it is the main book in the 'Programming in NLP' course) The books are available online for free (linked from the homepage). Paperbacks cost around 25 euro each make sure you get the latest version. Python documentation at the Python website: http://docs.python.org/.

Lectures Tuesdays, 10.15-12.00 The main goal of the lectures is to help you grasp the theoretical content of the course. Please mail me about parts of the course that you nd especially dicult, and I will try to include more material about it in the coming lectures. The slides are put on the course homepage after the lecture (as quickly as I can manage).

Assignments Assignment supervision: Tuesdays, 13.15-15.00 Fridays, 10.15-12.00 3 obligatory practical assignments, 1 optional, but recommended (this week). The assignments are done in groups of two. Do not make the mistake of being a passive member of a group! Switch control of the keyboard frequently!

Assignment 0: description Not obligatory, but highly recommended. A hands-on assignment, where you will be familiarized with both programming in Python and Language Technology. Do not except to understand everything! Just work your way through the examples. Chapter 1 of the NLTK book.

Exam Date: one of October 2031 (exact day yet to be decided) Grade: Pass with distinction, Pass, or Fail

Some general notes about this course Learning to program is like learning to play an instrument or ride a bicycle: you need to practice! If you have experience of some other programming language, this course will be easy... but if this is the rst time you program, please work hard and practice continuously Please also note that everything else in the program depends on that you properly learn the contents of this course.

Computer science crash course Computers are machines that solve computational problems mechanically To do anything useful, they need detailed instructions. Algorithm: a detailed step-by-step account of how to solve a problem. Programming language: a formal language to express algorithms.

Example of an algorithm Serves 4 100g slightly stale crusty white bread, soaked in cold water for 20 mins 1kg very ripe tomatoes, diced 1 ripe red pepper and 1 green pepper, deseeded and diced 1 medium cucumber, peeled and diced 2 cloves of garlic, peeled and crushed 150ml extra virgin olive oil 2tbsp sherry vinegar Salt, to taste Garnishes see below 1. Mix the diced tomatoes, peppers and cucumber with the crushed garlic and olive oil in the bowl of a food processor or blender. Squeeze out the bread, tear it roughly into chunks, and add to the mixture. 2. Blend until smooth, then add the salt and vinegar to taste and stir well. 3. Pass the mixture through a ne sieve, then cover and refrigerate until well chilled. 4. Serve with garnishes of your choice: I liked diced black olives, hard-boiled egg and small pieces of cucumber and pepper; mint or parsley also works well, and many people add spring onion, cubes of Spanish ham and so on.

Example: long division 0235,4... 1648 7 0 16 14 24 21 38 35 30 28...

Example: Swedish personal identity check digit For instance: 640823-323 1. Multiply every second digit by 2, leave the rest unchanged 12 4 0 8 4 3 6 2 6 2. Sum all the digits (note that 12 becomes 1 + 2) 1 + 2 + 4 + 0 + 8 + 4 + 3 + 6 + 2 + 6 = 36 3. The check digit is equal to 10 - d, where d is the last digit of the sum. (If this is 10, then 0). 640823-3234

Example: nding a name in the telephone book How do we nd a name in the telephone book?

Example: nding a name in the telephone book 1. Open the book roughly where you think the name would be (or in the middle) 2. Found the name? If yes, then we're done If the name would be on this page but isn't, then it is not listed 3. Select a new place to open the book: before or after the current position 4. Repeat from 2. Binary search more ecient than linear search! (logarithmic complexity faster than linear)

Discussion How do we nd the most frequent word in today's Göteborgsposten?

An example of a very short program print('hello!')

Editing Python program code Write the Python program in a text le, e.g. hello.py Specialized editors assist you (e.g. coloring) In the lab room, the TextMate tool is installed The text that you write is called the source code The text le (conventionally ending in.py) is called a source le or a script

Running a Python program Your code is executed (run) by a tool called the Python interpreter: python hello.py

The Python interpreter interactively The interpreter can also be run interactively:

Python interpreters online http://www.pythontutor.com/visualize.html also shows state of execution http: //www.compileonline.com/execute_python3_online.php http://ideone.com

Installing Python on your own machine https://www.python.org/downloads/ Follow the directions for your system (e.g. Windows, mac) Make sure that you install a recent version of Python (e.g. 3.4.1)

Versions of Python The Python 3 version was introduced in 2008 This version introduced a number of improvements to the Python language, mainly in how you deal with text However, due to these changes, the community has been slow to adopt Python 3 Many people still use Python 2 This is the rst year we teach Python 3

The anatomy of another short program x = 5 y = x*x + 1 print(x + y) text = 'This is a piece of text.' print(len(text))

Some Python terminology see Downey, chapter 2 statement: performs an action, such as printing a string or assigning a name to a value. statements are executed line by line values: basic things a program works with, like letters and numbers. expression: denotes a value, possibly after some computation (5+5 denotes 10). types: every value has a type, e.g., 5 is an integer, 'This is a piece of text' is a string. (text) variables: gives a name to a value.

When things go wrong: bugs Syntax errors are when the code is broken or incomplete. y = x*x + Runtime errors are errors, also referred to as exceptions, occurring while running a program.... such as trying to open a le that does not exist Semantic errors are errors where the program actually runs, but fails to do what we want.

Modular programming To be productive, we often need to build on what others have done. Instead of trying to reinvent the wheel, we often use code dened by others that helps us solve a particular problem. Modularity: breaking down a program into reusable parts. Python standard library is always available with the Python program. https://docs.python.org/3/library/index.html However, we will actually many times reinvent the wheel just for the practice.

The NLTK library for natural language processing NLTK (Natural Language ToolKit) is not a part of standard Python, it is a Python package that requires separate installation. NLTK covers a wide range of Language Technology subjects and methods. NLTK also provides many Language Technology resources, e.g., WordNet that we will work with in assignment 1.

Installing NLTK on your own computer Instructions are found here: http://www.nltk.org/download

Example: most frequent word in GP with open('göteborgsposten.txt') as f: table = {} for line in f: for word in line.split(): if table.has_key(word): table[word] += 1 else: table[word] = 1 print(max(table, key=table.get))

Next lecture Writing and running simple programs. Values, expressions, variables, types. Numbers, strings, lists. Conditions: if... Functions.