Basic Concepts. Computer Science. Programming history Algorithms Pseudo code. Computer - Science Andrew Case 2

Similar documents
Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components. Software{ User Programs. Operating System. Hardware

ENGR 101 Engineering Design Workshop

Getting Started Values, Expressions, and Statements CS GMU

Getting Started with Python

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Java Bytecode (binary file)

Algorithms and Programming I. Lecture#12 Spring 2015

Fundamentals of Programming (Python) Getting Started with Programming

Variables, expressions and statements

Professor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators

Lecture 27. Lecture 27: Regular Expressions and Python Identifiers

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an . Michigan State University CSE 231, Fall 2013

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

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

Variable and Data Type I

CHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS

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

Program Fundamentals

The Three Rules. Program. What is a Computer Program? 5/30/2018. Interpreted. Your First Program QuickStart 1. Chapter 1

Coral Programming Language Reference Manual

Variable and Data Type I

PROGRAMMING FUNDAMENTALS

Lecture Set 2: Starting Java

Lecture Set 2: Starting Java

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

Basics of Java Programming

Introduction to programming with Python

3. Java - Language Constructs I

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

Chapter 3: Operators, Expressions and Type Conversion

Table of Contents EVALUATION COPY

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

6.096 Introduction to C++ January (IAP) 2009

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

Course Outline. Introduction to java

Introduction to Programming

CS 1301 Exam 1 Answers Fall 2009

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

CSCE 110 Programming I Basics of Python: Variables, Expressions, Input/Output

Datatypes, Variables, and Operations

Welcome to Python 3. Some history

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

PROGRAMMING FUNDAMENTALS

Review. Input, Processing and Output. Review. Review. Designing a Program. Typical Software Development cycle. Bonita Sharif

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

Python I. Some material adapted from Upenn cmpe391 slides and other sources

Chapter 3 : Informatics Practices. Class XI ( As per CBSE Board) Python Fundamentals. Visit : python.mykvs.in for regular updates

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

Starting with a great calculator... Variables. Comments. Topic 5: Introduction to Programming in Matlab CSSE, UWA

Jython. secondary. memory

DEPARTMENT OF MATHS, MJ COLLEGE

Introduction to Problem Solving and Programming in Python.

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

More Programming Constructs -- Introduction

Here n is a variable name. The value of that variable is 176.

Introduction to Java Applications

What did we talk about last time? Examples switch statements

CS 115 Lecture 4. More Python; testing software. Neil Moore

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

Introduction to Computer Programming CSCI-UA 2. Review Midterm Exam 1

CS 231 Data Structures and Algorithms, Fall 2016

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Lecture 3. Input, Output and Data Types

An Introduction to Python (TEJ3M & TEJ4M)

Programming with Python

BASIC ELEMENTS OF A COMPUTER PROGRAM

Introduction to Computers. Laboratory Manual. Experiment #3. Elementary Programming, II

DaMPL. Language Reference Manual. Henrique Grando

Monty Python and the Holy Grail (1975) BBM 101. Introduction to Programming I. Lecture #03 Introduction to Python and Programming, Control Flow

Variables and Operators 2/20/01 Lecture #

CS 1301 Exam 1 Fall 2009

And Parallelism. Parallelism in Prolog. OR Parallelism

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

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

Python Unit

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

STEAM Clown & Productions Copyright 2017 STEAM Clown. Page 1

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

Java Fall 2018 Margaret Reid-Miller

06/11/2014. Subjects. CS Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / ) Beginning with Python

Constants. Variables, Expressions, and Statements. Variables. x = 12.2 y = 14 x = 100. Chapter

CS313D: ADVANCED PROGRAMMING LANGUAGE

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

Key Differences Between Python and Java

egrapher Language Reference Manual

CSCE 110 Programming I

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Full file at C How to Program, 6/e Multiple Choice Test Bank

CSCI 121: Anatomy of a Python Script

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

Primitive Data, Variables, and Expressions; Simple Conditional Execution

Transcription:

Basic Concepts Computer Science Computer - Science - Programming history Algorithms Pseudo code 2013 Andrew Case 2

Basic Concepts Computer Science Computer a machine for performing calculations Science Programming history Algorithms Pseudo code 2013 Andrew Case 3

Basic Concepts Computer Science Computer a machine for performing calculations Science knowledge and study of a subject Programming history Algorithms Pseudo code 2013 Andrew Case 4

Computer Components Software{ User Programs Operating System Hardware

What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point B from point A. A program may say... if starting at location B, go north 3 blocks, then go East 2 blocks.

Programming History Programming langauge tree: http://people.mandriva.com/~prigaux/language-study/di agram.png First programmer: Ada Lovelace Different paradigms Functional Procedural Object Oriented etc. 2013 Andrew Case 7

What are Programs? Input Processing Output

High/Low Level Programming Languages Low level programming languages are languages which have instruction sets that are limited and specific to the computer hardware being run on. Programmers need to know how the hardware works to use it. High level programming languages provide a layer of abstraction that allows for the programmer to only have to learn a hardware independent language to write software.

Low Level Languages Pros Can be more optimized Usually smaller executables Cons Platform dependent Slower development Harder to understand Easier to introduce bugs When to use it: Need extra optimization, Need small executables (embedded systems) Example: Assembly (different for each OS/Architecture)

High Level Languages Pros Faster development (libraries/etc.) Easier to understand (abstraction) Can be platform independent Cons Usually larger executables Abstraction layer usually adds overhead for processing resulting in slower executables When to use it: Need portability, need faster turn-around time for development, when programmer time is more valuable than processing time Examples: Java, C, C++, C#, Javascript, PHP, Perl, Python, Lisp, Scheme, R, etc.

Assembly Example (Low Level) mov ax,cs mov ds,ax mov ah,9 mov dx, offset Hello int 21h xor ax,ax int 21h Hello: db "Hello World!",13,10,"$"

Java Example (High Level) class HelloWorld { static public void main( String args[] ) { System.out.println( "Hello World!" ); } }

Python Example (High Level) print( hello World! )

Anatomy of a Program Traditional Language Source Code Interpreted Language Source Code Compiler Interpreter Compiled Code Byte Code Linker Virtual Machine Executable Execution

Bytecode vs. Executable Bytecode Cross platform Allows for replacement of small components without recompiling entire programs Generally slower performance Executable Runs on one platform Programs generally compile down to larger executables Generally faster performance

Interpreter In addition to bytecode, python provides a real time interpreter. An interpreter allows you to interactively provide statements and have python compile and run those statements on the fly. Provides fast and user friendly development environment easy way to debug programs no waiting around for code to compile.

Natural Languages Syntax: punctuation and spacing Grammar: forms well defined sentences (e.g. subject verb-object) Parts of speech: nouns, verbs, adjectives Semantics: The meaning of the words Example: The quick brow fox jumped over the lazy dog.

Programming Languages Syntax: punctuation (e.g. parentheses, colons, spacing) Grammar: forms well defined statements (e.g. if statement is true then perform subsequent statement) Parts of speech: keywords, variables, operators, etc. Semantics: The meaning of the words Example: if a == b: print( a is equal to b )

Coding Style Just as in natural languages the style of coding matters. Style determines the level of readability, maintainability, and efficiency. Several things make up a coding style: Formatting, Naming schemes, Comments, and more!

Algorithms

Algorithms A series of repeated instructions that solve a problem

Algorithms A series of repeated instructions that solve a problem For example: To read a file and print it's contents a program would: check if it has reached the end of a file, if not read a line and print it's contents, repeat To sort a list of numbers it could: compare the first two number, swap the number if necessary, then proceed to second and third numbers and repeat until all numbers are sorted

Bugs

Bugs All programmers run into bugs... lots and lots of bugs. Bugs are errors in a program. Bugs come in three different varieties:

Bugs All programmers run into bugs... lots and lots of bugs. Bugs are errors in a program. Bugs come in three different varieties: Compile time errors: (syntax/type/etc.) The rules of the language have been violated. Examples: improper spacing, missing colon, etc.

Bugs All programmers run into bugs... lots and lots of bugs. Bugs are errors in a program. Bugs come in three different varieties: Compile time errors: (syntax/type/etc.) The rules of the language have been violated. Examples: improper spacing, missing colon, etc. Runtime errors (crashes): Errors during execution Example: input file may not be readable

Bugs All programmers run into bugs... lots and lots of bugs. Bugs are errors in a program. Bugs come in three different varieties: Compile time errors: (syntax/type/etc.) The rules of the language have been violated. Examples: improper spacing, missing colon, etc. Runtime errors (crashes): Errors during execution Example: input file may not be readable Logic errors: A problem that is caused by a flawed algorithm or set of instructions used to solve a problem. Example: If you try to print the numbers 1-10 using 'range(10)' instead of 'range(1,11)'

Pseudo-Code The expression of programming logic in a language independent nature. Good for design phase of coding Examples: if student_grade >= 60 print passed else print failed

Writing a Program Design Write Code Fix Syntax Errors Run Program

Basic Programming Concepts Keywords Statements Operators Data Types Variables Assignment Constants

Python Keywords Keywords are reserved words that have special meaning in a particular programming language. These words can not be used for any other purpose (e.g. variable names). Python keywords are: False, class, finally, is, return, None, continue for, lambda, try, True, def, from, nonlocal, while, and, del, global, not, with, as, elif, if, or, yield, assert, else, import, pass, break, except, in, raise

Statements Programs are made up of a series of statements Similar to a sentence in a natural language, each statement presents a command that the interpreter understands The interpreter parses or reads the statement determines what is being requested and executes that statement

Data Types Integers (Real numbers): int Strings (Text): str Floating point numbers (decimals): float

Operators Different data types have different operators Operators can be part of a statement Operators act on the operands around them Unary operators (-3), Binary operators(1-3), Ternary operators (True if a<b else False)

Operators on Numbers (in order of precedence) Addition + Subtraction - Multiplication * Division / Division with integers// Remainder % Exponents **

Operators on Strings (str) Concatenation + Repetition *

Comments Provides: Documentation Clarifying what specific code is doing Make code easy for the author or other programmers to understand Line comments start with a '#' character Block comments start and end with either three single quotes (') or three double quotes (")

Comments Example # list number from 0 to 9 list(range(10)) '''This code will list number from -10 to -1''' list(range(-10,0)) """ This code will list numbers from -5 to 4""" list(range(-5,5))

Variables Names Variables are labels used by programmers for storage of data Variable name in python: Can be long Are case sensitive (Alpha!= alpha) Can contain letters, numbers, and underscores ( _ ) Must not start with a number Can not be a keyword

Variables Names (Examples) thisvariablenameisvalid = "valid naming conventions"

Variables Names (Examples) thisvariablenameisvalid = "valid naming conventions" this_variable_name_is_valid = "also valid"

Variables Names (Examples) thisvariablenameisvalid = "valid naming conventions" this_variable_name_is_valid = "also valid" names = "names are valid"

Variables Names (Examples) thisvariablenameisvalid = "valid naming conventions" this_variable_name_is_valid = "also valid" names = "names are valid" Names = "not the same as names"

Variables Names (Examples) thisvariablenameisvalid = "valid naming conventions" this_variable_name_is_valid = "also valid" names = "names are valid" Names = "not the same as names" numbers_between_0_and_9 = "another valid"

Variables Names (Examples) thisvariablenameisvalid = "valid naming conventions" this_variable_name_is_valid = "also valid" names = "names are valid" Names = "not the same as names" numbers_between_0_and_9 = "another valid" 0_9_can_not_start_a_name = "invalid"

Variables Names (Examples) thisvariablenameisvalid = "valid naming conventions" this_variable_name_is_valid = "also valid" names = "names are valid" Names = "not the same as names" numbers_between_0_and_9 = "another valid" 0_9_can_not_start_a_name = "invalid" if = "keywords are not allowed"

Variables Names (Examples) thisvariablenameisvalid = "valid naming conventions" this_variable_name_is_valid = "also valid" names = "names are valid" Names = "not the same as names" numbers_between_0_and_9 = "another valid" 0_9_can_not_start_a_name = "invalid" if = "keywords are not allowed" special_chars_!_allowed = "invalid"

Constants A constant is a stored value that doesn't change Used for things that will remain constant throughout the program. (e.g. pi, conversions between metric and standard units, etc) When representing data that doesn't change it's often a good idea to use constants In python, there is no such thing as a constant, but it's still good coding practice to use certain variables as constants Generally constants are in all CAPITAL letters

Variable Assignment Statements PI = 3.14159265 radius = 5 area_circle = PI * (radius**2)

Data Input For strings: name = input("what is your name? ") print("hello, " + name) For numbers: year = input("what year is your birthday? ") year = int(year) # convert string to integer print("you were born in " + str(year) + "?!") print("i have met many people born in " + str(year-1) + " and " + str(year+1) + " but never " + str(year))

Type Conversion In certain circumstances you data types may need to be converted to other data types (e.g. converting an string into an integer or vice versa). String Integer x = '14' int(x) or float(x) Integer or Floats String x = 14 str(x) Integer->Float (done by Python) 2.5*12 is equivalent to 2.5 * float(12)

Data Output Print built-in statement Print takes any number of arguments print('jack', 'and', 'jill') print('went up the hill') Print takes two special arguments at the end of the list of arguments: print('to', 'fetch', 'a', 'pail', sep = '.') print('to', 'fetch', 'a', 'pail', end = '.') print('to', 'fetch', 'a', 'pail', sep = '.', end = '\n') print('to', 'fetch', 'a', 'pail', end = '.', sep = '\n')

Data Output For numbers with strings: year = 2010 print('the year is ', year)

Data Output For numbers with strings: year = 2010 print('the year is ', year) print('the year is ' + year) # OK

Data Output For numbers with strings: year = 2010 print('the year is ', year) # OK print('the year is ' + year) # TypeError print('the year is ' + str(year)) # OK