COSC 1306 COMPUTER SCIENCE AND PROGRAMMING

Slides:



Advertisements
Similar presentations
Lecture Notes 1/21/04 Program Design & Intro to Algorithms.
Advertisements

Chapter 16 Programming and Languages: Telling the Computer What to Do.
1 Programming Languages Examples: C, Java, HTML, Haskell, Prolog, SAS Also known as formal languages Completely described and rigidly governed by formal.
Introduction to Programming (in C++) Introduction Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC.
COSC 1306—COMPUTER SCIENCE AND PROGRAMMING FLOATING-POINT NUMBERS Jehan-François Pâris
Computer Science 101 Introduction to Programming.
1 I.Introduction to Algorithm and Programming Algoritma dan Pemrograman – Teknik Informatika UK Petra 2009.
Introduction to High-Level Language Programming
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
Introducing Java.
P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Compilers, Interpreters and Debuggers Ruibin Bai (Room AB326) Division of Computer Science.
Introduction to Python
Introduction to Computational Linguistics Programming I.
Computer Science 101 Introduction to Programming.
Programming Lifecycle
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Python From the book “Think Python”
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING Jehan-François Pâris
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
8 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
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.
The single most important skill for a computer programmer is problem solving Problem solving means the ability to formulate problems, think creatively.
INTRODUCTION TO COMPUTER PROGRAMMING(IT-303) Basics.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING Jehan-François Pâris
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
Lecture 1b- Introduction
Component 1.6.
Department of Computer Science,
Introduction to Computing Science and Programming I
14 Compilers, Interpreters and Debuggers
A Python Tour: Just a Brief Introduction
Topic: Programming Languages and their Evolution + Intro to Scratch
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING
GCSE COMPUTER SCIENCE Practical Programming using Python
GCSE COMPUTER SCIENCE Practical Programming using Python
Introduction to programming
Lecture 1 Introduction Richard Gesick.
CSCI-235 Micro-Computer Applications
Lecture 1: Introduction to JAVA
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING
Programming Mehdi Bukhari.
A451 Theory – 7 Programming 7A, B - Algorithms.
Introduction to Programming
Application Development Theory
Introduction to Programming
CS190/295 Programming in Python for Life Sciences: Lecture 1
String Output ICS 111: Introduction to Computer Science I
Introduction CSC 111.
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING
Introduction to Programming
PROGRAMMING FUNDAMENTALS Lecture # 03. Programming Language A Programming language used to write computer programs. Its mean of communication between.
15-110: Principles of Computing
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
12th Computer Science – Unit 5
Chapter 1: Programming Basics, Python History and Program Components
Computer Programming-1 CSC 111
1.3.7 High- and low-level languages and their translators
WJEC GCSE Computer Science
Programming language translators
Instructor: Alexander Stoytchev
Dasar-Dasar Pemrograman 2: Java Basics
Introduction to Computer Science
Week 1 - Friday COMP 1600.
Presentation transcript:

COSC 1306 COMPUTER SCIENCE AND PROGRAMMING Jehan-François Pâris jfparis@uh.edu Fall 2016 1

THE ONLINE BOOK CHAPTER I GENERAL INTRODUCTION

Problem solving Given a problem, find a solution Should be Correct Accurate Complete We want an algorithm

Why? Once we have an algorithmic solution for a problem, we can convert it into a program Let a computer solves many instances of the problem Algorithms existed before computers existed Euclid’s algorithm, … Computers made them more important

What defines an algorithm Must always produce the right result Under all circumstances Instructions should be well-defined Anybody using the algorithm should obtain the same answer Should have a finite number of steps Cannot run forever

These are not algorithms On a shampoo bottle: Lather Rinse Repeat

These are not algorithms On a shampoo bottle: Lather Rinse Repeat How many times?

These are not algorithms On fuel tank cap: Turn until three o'clock

These are not algorithms On fuel tank cap: Turn until three o'clock Ambiguous!

Python High-level interpreted language Created by Guido Van Rossum Named after Monty Python's Flying Circus BBC comedy series of early 70’s

High-level languages Have replaced assembler Increase programmer’s productivity Can run on multiple architectures Intel/AMD and ARM Must be translated into machine language before being executed Two approaches Compiled languages Interpreted languages

Compiled languages Programs written in old Fortran, C, C++ and so go through a program that translates them into directly executable code The compiler Doing g++ myprogram.cpp –o myprogram produces an executable file called myprogram that can run anytime No need to recompile

C program C compiler Executable Results Computer Once Every time

Advantages The executable can run on any computer with Same CPU instruction set Same—or compatible—operating system We can sell copies of the executable without revealing the secrets of our program Reverse engineering is possible but very time-consuming

Interpreted languages Languages like Python and Ruby are not compiled Translated again and again into bytecode each time we execute them Bytecode is interpreted by the language interpreter

translates and executes Source code Python Interpreter: translates and executes the program Every time Results

Advantages Platform independence: Bytecode can run on any platform for which there is an interpreter Dynamic typing: Same variable can refer to a string then an integer then … Smaller executable sizes

Disadvantages Portability limitations : Bytecode will not run on any machine on which the interpreter was not installed. Speed: Bytecode is not optimized for a specific architecture Just-in-time compilation introduces delays Cannot sell copies of a program without revealing its source code

A partial solution In many cases, speed is not an issue outside of loops than get executed thousand and thousands of times Loops inside other loops Can rewrite code for these inner loops in C and include this code into a Python program Use Python C API

Neither fish nor fowl Java is compiled Like C into bytecode Like Python Bytecode is executed by Java Virtual Machine

A comparison Compiled languages Translate once the whole program into an executable Fast Can run on any machine having same architecture and same OS Interpreted languages Translate programs line by line each time they are executed Much slower Can run on any machine having the interpreter installed

Programs Specify a sequence of instructions to be executed by a computer The order of the instructions specify their order of execution

Example Informal sales_tax = total_taxable × tax_rate with tax_rate = 0.0825 Python taxRate = 0.0825 salesTax = totalTaxable*taxRate

My first Python program print("I add two numbers, 2 and 3") print(2 + 3) It’s “print” and not “Print” Cannot use smart quotes Semicolons are optional and nobody uses them

Types of instructions Input & output name = input("Enter your name: ") print("Hello! ") Math and logic celsius = (fahrenheit - 32)*5/9 Conditional execution if celsius > 100 : Repetition for all lines in myfile:

Debugging Finding what’s wrong in your program Finding the problem Hardest Fixing the error

Types of errors Syntax errors print("Hello!) # missing closing quotes print("Hello!") # correct A big annoyance Especially for beginners Everyone ends better at it

Types of errors Run-time errors/Exceptions Division by zero A forgotten special case

Types of errors Semantic errors Your solution is wrong You expressed it poorly taxRate = 8.25 # in percent! salesTax = totalTaxable*taxRate

Experimental debugging (I) Modify your program until it works?

Experimental debugging (II) Look at your program Try to explain it to yourself, to friends Do not let them copy your code! Add print statements after each step Remove them or better comment them out when they are not needed anymore.

Experimental debugging (III) Act as if you are investigating a mystery

Natural and formal languages Natural languages are complex, tolerate ambiguities, often have to be taken figuratively I am literally dying of thirst Could you bring me a glass of water? Formal languages are simpler, have much more strict syntax rules, and want to be unambiguous What they say will be taken literally

Natural language ambiguities KIDS MAKE NUTRITIOUS SNACKS STOLEN PAINTING FOUND BY TREE QUEEN MARY HAVING BOTTOM SCRAPED MILK DRINKERS ARE TURNING TO POWDER SQUAD HELPS DOG BITE VICTIM

My first program print("I add two numbers, 2 and 3") print(2 + 3) It’s “print” and not “Print” Cannot use smart quotes Semicolons are optional and nobody uses them

Interactive Python Requires Javascript to be authorized for at least interactivepython.org

Commenting Main purpose To help human readers understand your programs Becomes more important as program sizes grow To record who wrote the program, when it happened and so on

In-line comments Anything following a pound sign (“#”) is ignored by the Python interpreter print ("Hello World!") print ("Hello World!") # what to say? r = d/2 # compute radius of circle #Begin main loop

Multi-line comments Anything between three double quotes—"""—is ignored by the Python interpreter """ Tell what the program does Jehan-Francois Paris Assignment # 1 COSC 1306 MW 2:30-4:00 Fall 2017 """ At the beginning of each program