PROGRAMMING FUNDAMENTALS

Similar documents
PROGRAMMING FUNDAMENTALS

PROGRAMMING FUNDAMENTALS

How to Think Like a Computer Scientist: Learning with Python 3»

An Introduction to Python (TEJ3M & TEJ4M)

PRG PROGRAMMING ESSENTIALS. Lecture 2 Program flow, Conditionals, Loops

Python The way of a program. Srinidhi H Asst Professor Dept of CSE, MSRIT

Algorithms and Programming I. Lecture#12 Spring 2015

PYTHON PROGRAMMING FOR ENGINEERS AND SCIENTISTS

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

Act like a code monkey Coding Basics

Welcome to Python 3. Some history

CS102 Unit 2. Sets and Mathematical Formalism Programming Languages and Simple Program Execution

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2

Unit E Step-by-Step: Programming with Python

Python notes from codecademy. Intro: Python can be used to create web apps, games, even a search engine.

Program Abstractions, Language Paradigms. CS152. Chris Pollett. Aug. 27, 2008.

CS152 Programming Language Paradigms Prof. Tom Austin, Fall Syntax & Semantics, and Language Design Criteria

CSC 015: FUNDAMENTALS OF COMPUTER SCIENCE I

Fundamentals of Programming (Python) Getting Started with Programming

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

CS101 Introduction to Programming Languages and Compilers

What you get When you install Python for your computer, you get a number of features:

Python Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

Individual research task. You should all have completed the research task set last week. Please make sure you hand it in today.

CS 3813/718 Fall Python Programming. Professor Liang Huang.

Getting Started with Python

Lecture 1. basic Python programs, defining functions

Python Basics. level 1 Chris Roffey

Introduction to Programming

Seminar in Programming Languages

Introduction to computers and Python. Matthieu Choplin

Component V Supporting Materials / Learn More Interesting Facts. Interesting Facts

How to Think Like a Computer Scientist: Learning with Python 3 Documentation

! Broaden your language horizons. ! Study how languages are implemented. ! Study how languages are described / specified

The current topic: Python. Announcements. Python. Python

Computing and compilers

PYTHON 3 6 TUTORIAL epoint.edu.vn PYTHON 3 6 TUTORIAL. page 1 / 5

PYTHON FOR BEGINNERS A CRASH COURSE GUIDE TO LEARN PYTHON IN 1 WEEK CODING PROGRAMMING WEB PROGRAMMING PROGRAMMER

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

Python 3 Object Oriented Programming Second Edition Building Robust And Maintainable Software With Object Oriented Design Patterns In Python

DSC 201: Data Analysis & Visualization

Objective: To learn meaning and concepts of programming. Outcome: By the end of this students should be able to describe the meaning of programming

Introduction to Programming in Python (1)

Administration Computers Software Algorithms Programming Languages

/ Cloud Computing. Recitation 2 January 19 & 21, 2016

What is programming? Elements of Programming Languages. From machine code to programming languages. What is a programming language?

programming for beginners 3 manuscripts in 1 bundle python for beginners java programming and html css for beginners

SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

Chapter 9. Introduction to High-Level Language Programming. INVITATION TO Computer Science

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

Programming in Python

Technical Documentation Version 7.2 RPL Language Structure

COMP 3002: Compiler Construction. Pat Morin School of Computer Science

Google Docs Tipsheet. ABEL Summer Institute 2009

Python Input, output and variables

PC4G - University of Waterloo December 8, 2017

Try typing the following in the Python shell and press return after each calculation. Write the answer the program displays next to the sums below.

Program development plan

Python Input, output and variables. Lecture 22 COMPSCI111/111G SS 2016

CS164: Midterm I. Fall 2003

Handout 9: Imperative Programs and State

Chapter 1: Building Blocks of Programming

WELCOME! (download slides and.py files and follow along!) LECTURE 1

Variables and. What Really Happens When You Run hello_world.py

CMSC 330: Organization of Programming Languages. Administrivia

Programming II (CS300)

Welcome to CS 115 (Winter 2019)

CHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS

CSC 326H1F, Fall Programming Languages. What languages do you know? Instructor: Ali Juma. A survey of counted loops: FORTRAN

WHY EFFECTIVE WEB WRITING MATTERS Web users read differently on the web. They rarely read entire pages, word for word.

Python for Informatics

Table of Contents EVALUATION COPY

Principles of computer programming. Profesor : doc. dr Marko Tanasković Assistent : doc. dr Marko Tanasković

Abcs Of Z/os System Programming Volume 8 international technical support organization abcs of z/os system programming volume 8 july 2012 sg

Introduction to programming (LT2111) Lecture 1: Introduction

Lecture 01 & 02 Computer Programming

Com S 541. Programming Languages I

DATA 301 Introduction to Data Analytics Python. Dr. Ramon Lawrence University of British Columbia Okanagan

LECTURE 1. Getting Started with Python

CMPT 120 Basics of Python. Summer 2012 Instructor: Hassan Khosravi

Full file at

Software. Programming Languages. Types of Software. Types of Languages. Types of Programming. Software does something

CSci 160 Computing Science I. Sarah Carruthers Fall 2017

Introduction to Compilers and Language Design Copyright (C) 2017 Douglas Thain. All rights reserved.

Introduction to: Computers & Programming: Review prior to 1 st Midterm

Programming. We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems.

Chris Simpkins (Georgia Tech) CS 2316 Data Manipulation for Engineers Python Overview 1 / 9

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

Welcome to CS 115 (Winter 2018)

Java Programming Unit 3: Variables and Arithmetic Operations

DOWNLOAD OR READ : LEARN PYTHON 3 THE HARD WAY PDF EBOOK EPUB MOBI

DM550 Introduction to Programming part 2. Jan Baumbach.

Starting Out With Python Solutions

Introduction to Programming Style

CIS192: Python Programming

Outline. Introduction to Programming (in C++) Introduction. First program in C++ Programming examples

Invitation to Computer Science 7th Edition TEST BANK Schneider Gersting

CS 1044 Program 6 Summer I dimension ??????

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

Transcription:

PROGRAMMING FUNDAMENTALS INTRODUCTION & THE WAY OF THE PROGRAM João Correia Lopes INESC TEC, FEUP 25 September 2018 FPRO/MIEIC/2018-19 25/09/2018 1 / 33

INTRODUCTION GOALS By the end of this class, the student should be able to: Describe the goals, methods and assessment of the Unit Describe introductory concepts on Problem solving, Algorithms and Programming Languages Describe the concepts of program, errors and debugging FPRO/MIEIC/2018-19 25/09/2018 2 / 33

INTRODUCTION TIPS There s no slides: we use a script and some illustrations in the class. That is NO replacement for reading the bibliography listed in the class sheet Students are responsible for anything that transpires during a class therefore if you re not in a class, you should get notes from someone else (not the instructor) David Mayer The best thing to do is to read carefully and understand the documentation published in the Content wiki (or else ask in the class) We will be using Moodle as the primary means of communication FPRO/MIEIC/2018-19 25/09/2018 3 / 33

INTRODUCTION PHYTON TEACHING https://web.fe.up.pt/~jlopes/doku.php/teach/fpro/resources FPRO/MIEIC/2018-19 25/09/2018 4 / 33

INTRODUCTION MONTY PHYTON TEACHING https://www.youtube.com/watch?v=q3iaqxnpq-a FPRO/MIEIC/2018-19 25/09/2018 5 / 33

INTRODUCTION And Now for Something Completely Different! FPRO/MIEIC/2018-19 25/09/2018 6 / 33

Part I PRESENTATION OF THE COURSE FPRO/MIEIC/2018-19 25/09/2018 7 / 33

CONTENTS 1 GOALS 2 CONTENT 3 ASSESSMENT FPRO/MIEIC/2018-19 25/09/2018 8 / 33

GOALS UNIT GOALS The global aim of this Unit is to give the student the ability to create algorithms, and to use a programming language to implement, test, and debug algorithms for solving simple problems. The student will be able to understand and use the fundamental programming constructs, and the Functional approach to programming, specifically effect-free programming where function calls have no side-effects and variables are immutable, and contrast it with the Imperative approach. https://web.fe.up.pt/~jlopes/doku.php/teach/fpro/sheet FPRO/MIEIC/2018-19 25/09/2018 9 / 33

GOALS UNIT GOALS The global aim of this Unit is to give the student the ability to create algorithms, and to use a programming language to implement, test, and debug algorithms for solving simple problems. The student will be able to understand and use the fundamental programming constructs, and the Functional approach to programming, specifically effect-free programming where function calls have no side-effects and variables are immutable, and contrast it with the Imperative approach. https://web.fe.up.pt/~jlopes/doku.php/teach/fpro/sheet FPRO/MIEIC/2018-19 25/09/2018 9 / 33

CONTENT BIBLIOGRAPHY Peter Wentworth, Jeffrey Elkner, Allen B. Downey, and Chris Meyers, How to Think Like a Computer Scientist Learning with Python 3, 2012 [PDF] [HTML] Brad Miller and David Ranum, Learning with Python: Interactive Edition. Based on material by Jeffrey Elkner, Allen B. Downey, and Chris Meyers [HTML] Steven F. Lott, Building Skills in Python - A Programmer s Introduction to Python, FreeTechBooks, 2010 [HTML] David Mertz, Functional Programming in Python, O Reilly Media, 2015 [PDF] FPRO/MIEIC/2018-19 25/09/2018 10 / 33

CONTENT BIBLIOGRAPHY Peter Wentworth, Jeffrey Elkner, Allen B. Downey, and Chris Meyers, How to Think Like a Computer Scientist Learning with Python 3, 2012 [PDF] [HTML] Brad Miller and David Ranum, Learning with Python: Interactive Edition. Based on material by Jeffrey Elkner, Allen B. Downey, and Chris Meyers [HTML] Steven F. Lott, Building Skills in Python - A Programmer s Introduction to Python, FreeTechBooks, 2010 [HTML] David Mertz, Functional Programming in Python, O Reilly Media, 2015 [PDF] FPRO/MIEIC/2018-19 25/09/2018 10 / 33

CONTENT BIBLIOGRAPHY Peter Wentworth, Jeffrey Elkner, Allen B. Downey, and Chris Meyers, How to Think Like a Computer Scientist Learning with Python 3, 2012 [PDF] [HTML] Brad Miller and David Ranum, Learning with Python: Interactive Edition. Based on material by Jeffrey Elkner, Allen B. Downey, and Chris Meyers [HTML] Steven F. Lott, Building Skills in Python - A Programmer s Introduction to Python, FreeTechBooks, 2010 [HTML] David Mertz, Functional Programming in Python, O Reilly Media, 2015 [PDF] FPRO/MIEIC/2018-19 25/09/2018 10 / 33

ASSESSMENT GRADES 10% LE + 10% RE + 40% PE + 40% TE Do not exceed the absences limit (25% of total) A minimum classification of 40% on PE A minimum classification of 40% in the component TE Read the full story FPRO/MIEIC/2018-19 25/09/2018 11 / 33

ASSESSMENT TIME FOR KAHOOT! https://play.kahoot.it/#/?quizid=fe8160ee-e2c2-44e7-9c12-2c0395e51d29 FPRO/MIEIC/2018-19 25/09/2018 12 / 33

Part II THE WAY OF THE PROGRAM FPRO/MIEIC/2018-19 25/09/2018 13 / 33

CONTENTS 1 COMPUTERS, ALGORITHMS AND PROGRAMS 2 THE WAY OF THE PROGRAM FPRO/MIEIC/2018-19 25/09/2018 14 / 33

COMPUTERS, ALGORITHMS AND PROGRAMS COMPUTER SCIENTISTS Like mathematicians, computer scientists use formal languages to denote ideas (specifically computations). Like engineers, they design things, assembling components into systems and evaluating tradeoffs among alternatives. Like scientists, they observe the behavior of complex systems, form hypotheses, and test predictions. FPRO/MIEIC/2018-19 25/09/2018 15 / 33

COMPUTERS, ALGORITHMS AND PROGRAMS PROBLEM SOLVING The single most important skill for a computer scientist is problem solving. Problem solving means the ability to formulate problems, think creatively about solutions, and express a solution clearly and accurately. The process of learning to program is an excellent opportunity to practice problem-solving skills. FPRO/MIEIC/2018-19 25/09/2018 16 / 33

COMPUTERS, ALGORITHMS AND PROGRAMS ALGORITHM A set of specific steps for solving a category of problems steps + flow + stop decision FPRO/MIEIC/2018-19 25/09/2018 17 / 33

COMPUTERS, ALGORITHMS AND PROGRAMS VON NEUMANN ARCHITECTURE https://www.computerscience.gcse.guru/theory/von-neumann-architecture FPRO/MIEIC/2018-19 25/09/2018 18 / 33

COMPUTERS, ALGORITHMS AND PROGRAMS HIGH-LEVEL LANGUAGES Low-level languages (machine languages or assembly languages), are the only languages a computer executes; Thus, programs written in a high-level language have to be translated into something more suitable before they can run; Python is an example of a high-level language; Other high-level languages you might have heard of are C++, PHP, Pascal, C#, and Java. FPRO/MIEIC/2018-19 25/09/2018 19 / 33

COMPUTERS, ALGORITHMS AND PROGRAMS PYTHON INTERPRETER There are two ways to use it: In immediate mode, you type Python expressions into the Python Interpreter window, and the interpreter immediately shows the result; In script mode, you can write a program in a file and use the interpreter to execute the contents of the file. Spyder3 FPRO/MIEIC/2018-19 25/09/2018 20 / 33

COMPUTERS, ALGORITHMS AND PROGRAMS TIME FOR KAHOOT! https://play.kahoot.it/#/?quizid=1f83b3ec-3aec-4fae-a52d-4a4a873bb1e5 FPRO/MIEIC/2018-19 25/09/2018 21 / 33

THE WAY OF THE PROGRAM PYTHON 1 #!/usr/bin/env python3 3 import datetime now = datetime.datetime.now() 5 print() 7 print("current date and time using str method of datetime object:") print() 9 print(str(now)) 11 print() print("current date and time using instance attributes:") 13 print() print("current year: %d" % now.year) 15 print("current month: %d" % now.month) print("current day: %d" % now.day) 17 print("current hour: %d" % now.hour) print("current minute: %d" % now.minute) 19 print("current second: %d" % now.second) print("current microsecond: %d" % now.microsecond) 21 print() 23 print("current date and time using strftime:") print(now.strftime("%y-%m-%d %H:%M")) https://github.com/fpro-admin/lectures/blob/master/01/basics.py FPRO/MIEIC/2018-19 25/09/2018 22 / 33

THE WAY OF THE PROGRAM 1.1 THE PYTHON PROGRAMMING LANGUAGE Python is an interpreted high-level programming language for general-purpose programming Created by Guido van Rossum and first released in 1991, Python has a design philosophy that emphasizes code readability, notably using significant whitespace. It provides constructs that enable clear programming on both small and large scales Python features a dynamic type system and automatic memory management It supports multiple programming paradigms, including imperative, functional, procedural and object-oriented It has a large and comprehensive standard library FPRO/MIEIC/2018-19 25/09/2018 23 / 33

THE WAY OF THE PROGRAM 1.2 WHAT IS A PROGRAM? A program is a sequence of instructions that specifies how to perform a computation A few basic instructions appear in just about every language: INPUT Get data from the keyboard, a file, or some other device (such as a sensor) OUTPUT Display data on the screen or send data to a file or other device (such as a motor) MATH Perform basic mathematical operations like addition and multiplication CONDITIONAL EXECUTION Check for certain conditions and execute the appropriate sequence of statements REPETITION Perform some action repeatedly, usually with some variation FPRO/MIEIC/2018-19 25/09/2018 24 / 33

THE WAY OF THE PROGRAM 1.2 WHAT IS A PROGRAM? A program is a sequence of instructions that specifies how to perform a computation A few basic instructions appear in just about every language: INPUT Get data from the keyboard, a file, or some other device (such as a sensor) OUTPUT Display data on the screen or send data to a file or other device (such as a motor) MATH Perform basic mathematical operations like addition and multiplication CONDITIONAL EXECUTION Check for certain conditions and execute the appropriate sequence of statements REPETITION Perform some action repeatedly, usually with some variation FPRO/MIEIC/2018-19 25/09/2018 24 / 33

THE WAY OF THE PROGRAM 1.3 WHAT IS DEBUGGING? Programming is a complex process, and because it is done by human beings, it often leads to errors Programming errors are called bugs and the process of tracking them down and correcting them is called debugging. Wikipedia FPRO/MIEIC/2018-19 25/09/2018 25 / 33

THE WAY OF THE PROGRAM 1.4 SYNTAX ERRORS Syntax refers to the structure of a program and the rules about that structure For example, in English, a sentence must begin with a capital letter and end with a period Python can only execute a program if the program is syntactically correct; otherwise, the process fails and returns an error message FPRO/MIEIC/2018-19 25/09/2018 26 / 33

THE WAY OF THE PROGRAM 1.5 RUNTIME ERRORS A runtime error does not appear until you run the program. These errors are also called exceptions because they usually indicate that something exceptional (and bad) has happened. FPRO/MIEIC/2018-19 25/09/2018 27 / 33

THE WAY OF THE PROGRAM 1.6 SEMANTIC ERRORS With a semantic error in your program, it will run successfully, but it will not do the right thing The problem is that the program you wrote is not the program you wanted to write The meaning of the program (its semantics) is wrong FPRO/MIEIC/2018-19 25/09/2018 28 / 33

THE WAY OF THE PROGRAM 1.7 EXPERIMENTAL DEBUGGING One of the most important skills you will acquire is debugging. Although it can be frustrating, debugging is one of the most intellectually rich, challenging, and interesting parts of programming. In some ways, debugging is like detective work (clues, inference,...) Debugging is also like an experimental science FPRO/MIEIC/2018-19 25/09/2018 29 / 33

THE WAY OF THE PROGRAM 1.8 FORMAL AND NATURAL LANGUAGES Natural languages are the languages that people speak, such as English Formal languages are languages that are designed by people for specific applications For example, the math notation is a formal language that is particularly good at denoting relationships among numbers and symbols Programming languages are formal languages designed to express computations. Syntax rules: tokens & structure Parsing a statement is needed to determine its structure FPRO/MIEIC/2018-19 25/09/2018 30 / 33

THE WAY OF THE PROGRAM 1.9 A TYPICAL FIRST PROGRAM (WITH BONUS) # my first variable 2 greeting = "Hello" 4 # # COMMENTING LINES ####### 6 # # to comment MANY lines at a time, highlight all of them then CTRL+1 8 # do CTRL+1 again to uncomment them; # try it on the next two commented lines below! 10 whoami = "jlopes" 12 greeting = greeting + " " + whoami 14 # output the greeting print("\n" + greeting + "!") 16 # 18 #### AUTOCOMPLETE ####### # 20 # Spyder can autocomplete names for you. # Start typing a variable name defined in your program and hit tab 22 # before you finish typing; https://github.com/fpro-admin/lectures/blob/master/01/hello.py FPRO/MIEIC/2018-19 25/09/2018 31 / 33

THE WAY OF THE PROGRAM 1.10 COMMENTS A comment in a computer program is text that is intended only for the human reader It is completely ignored by the interpreter #--------------------------------------------------- 2 # This demo program shows off how elegant Python is! # Written by John Snow, December 2015. 4 #--------------------------------------------------- 6 print("hello, World!") # Isn t this easy! https://github.com/fpro-admin/lectures/blob/master/01/comments.py FPRO/MIEIC/2018-19 25/09/2018 32 / 33

THE WAY OF THE PROGRAM 1.10 COMMENTS A comment in a computer program is text that is intended only for the human reader It is completely ignored by the interpreter #--------------------------------------------------- 2 # This demo program shows off how elegant Python is! # Written by John Snow, December 2015. 4 #--------------------------------------------------- 6 print("hello, World!") # Isn t this easy! https://github.com/fpro-admin/lectures/blob/master/01/comments.py FPRO/MIEIC/2018-19 25/09/2018 32 / 33

THE WAY OF THE PROGRAM EXERCISES Moodle activity at: LE01: The way of the program FPRO/MIEIC/2018-19 25/09/2018 33 / 33