Programming Languages Programming languages are a compromise between spoken language and formal math. They allow humans to communicate with computers at.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Types and Arithmetic Operators
Programming in python Lesson 2.
Lecture 2 Introduction to C Programming
10-Jun-15 Just Enough Java. Variables A variable is a “box” that holds data Every variable has a name Examples: name, age, address, isMarried Variables.
Python (yay!) November 16, Unit 7. Recap We can store values in variables using an assignment statement >>>x = We can get input from the user using.
Python Programming: An Introduction to Computer Science
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
C++ for Engineers and Scientists Third Edition
Chapter 3 Computing with Numbers
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
Introduction to Python and programming Michael Ernst UW CSE 190p Summer 2012.
Python Control of Flow.
Computer Graphic with Programming Ching-Shoei Chiang, Fall 2013 Most of the teaching material is from Prof. Hoffmann, Purdue University BASICS Course Mechanics.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 3 Computing with Numbers.
Python Programming: An Introduction to Computer Science
Python Programming: An Introduction to Computer Science Chapter 3 Computing with Numbers Python Programming, 2/e1.
Lecture 2 - Variables, program execution, calculations, print() COMPSCI 101 Principles of Programming.
Announcements Class / Recitation slides available on the syllabus page Check morning of for latest version We will start grading clickers next lecture.
Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1.
Intro to Programming Problem 1: Computers have to be told exactly what do to. Problem 2: Computers only understand “Machine language”. Problem 3: Machine.
CIS Computer Programming Logic
Introduction to Python
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Munster Programming Training
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
CSC1015F – Chapter 3, Computing with Numbers Michelle Kuttel
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Using Pre-written C Functions Need the following information –Name of the function –Types of the input parameters –Return type of the function Use the.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
Computer Science 210 Computer Organization Introduction to Boolean Algebra.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Introduction to Algorithms. What is Computer Science? Computer Science is the study of computers (??) This leaves aside the theoretical work in CS, which.
Introduction to Python and programming Ruth Anderson UW CSE 140 Winter
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
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.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
Inside Class Methods Chapter 4. 4 What are variables? Variables store values within methods and may change value as the method processes data.
Today… Operators, Cont. Operator Precedence Conditional Statement Syntax. Winter 2016CISC101 - Prof. McLeod1.
Announcements Reading Read Chapter 4 (functions).
 Type Called bool  Bool has only two possible values: True and False.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
1 Sections 3.1 – 3.2a Basic Syntax and Semantics Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Fundamentals of Programming I Overview of Programming
Control Structures I Chapter 3
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Based on slides by Shawn.
Announcements Reading Project1 Codelab: Read Chapter 4 (functions)
Python Programming: An Introduction to Computer Science
Computer Science 210 Computer Organization
Introduction to Python
Data Types, Identifiers, and Expressions
Chapter 10 Programming Fundamentals with JavaScript
Introduction to Python
Bools and simple if statements
Computer Science 210 Computer Organization
15-110: Principles of Computing
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
SE1H421 Procedural Programming LECTURE 4 Operators & Conditionals (1)
Introduction to Value-Returning Functions: Generating Random Numbers
Chapter 2 Programming Basics.
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
月夜憶舍弟 戍鼓斷人行,邊秋一雁聲。 露從今夜白,月是故鄉明。 有弟皆分散,無家問死生。 寄書長不達,況乃未休兵。 杜甫
月夜憶舍弟 戍鼓斷人行,邊秋一雁聲。 露從今夜白,月是故鄉明。 有弟皆分散,無家問死生。 寄書長不達,況乃未休兵。 杜甫
General Computer Science for Engineers CISC 106 Lecture 03
Class code for pythonroom.com cchsp2cs
Hardware is… Software is…
 A function is a named sequence of statement(s) that performs a computation. It contains  line of code(s) that are executed sequentially from top.
Presentation transcript:

Programming Languages Programming languages are a compromise between spoken language and formal math. They allow humans to communicate with computers at a higher level than machine instructions Note: Software can usually be created using different programming languages, such as Java, Python, C++, etc.

Languages Cont. The easier the language is for humans to use, the harder it is for a computer to interpret. Natural language is ambiguous: Fruit flies like bananas I never said she took the money There are many languages at many different ‘levels’ of complexity and convenience.

Grammar and Syntax Languages have a set grammar and syntax Defines a “valid” program Punctuation: “,. ! ; : ?” always follows a word in English. Words are the basic building block in English

Building Blocks of Python Numbers, booleans, strings, floating point numbers, and variables are basic building blocks of Python True for most programming languages Keywords Python’s grammar defines how these building blocks fit together

Grammar Check When executing a python program IDLE will tell you when your grammar is incorrect Given as error messages

Numbers in Python Python allows us to work with familiar base 10 numbers. This is an example of the utility of programming languages. Numbers in python have various types. 1.0 vs 1 Note: Python needs to be told what type of math you want to do

Booleans Booleans are truth values True or False (both are keywords in Python) Booleans also have a type: bool

Boolean Values True, False Result of comparison, e.g. x < y Boolean operations: And:True and False ≡ False (x >= 5) and (x <= 10) Or:True or False ≡ True (x 10) Not:not True ≡ False not (3 == 4)

Precedence Question Consider a*b+c*d; which of the three is it equal to? A. (a*b) + (c*d) B. a * (b+c) * d C. ((a * b) + c) * d

Precedence Multiplication and division take precedence over addition and subtraction Consider a*b+c*d; which of the three is it equal to? A. (a*b) + (c*d) B. a * (b+c) * d C. ((a * b) + c) * d What about comparison ( =, >) vs. Boolean ops (and, or, not)? Comparisons take precedence …

Python Grammar Code in python consists of one of several things Statement Function Declaration Function Call Loop Conditional

Statements These are the most basic elements in python code Statements fit on a single line and typically Assign a value to a variable Perform arithmetic Print something Call functions or procedures

Examples print(“Hello”) print(“Hello” + “World”) print(abs(-1)) print(1.0/2.0) print(1/2)

Using Python as a Calculator In the interactive mode you can type statements for python to evaluate >>> >>> 10/2 5 >>> 10%2 0

Using the Math Library Besides (+, -, *, /, //, **, %, abs), we have lots of other math functions available in a math library. A library is a module with some useful definitions/functions.

Using the Math Library Let ’ s write a program to compute the roots of a quadratic equation! The only part of this we don ’ t know how to do is find a square root … but it ’ s in the math library!

Using the Math Library To use a library, we need to make sure this line is in our program: import math Importing a library makes whatever functions are defined within it available to the program.

Using the Math Library To access the sqrt library routine, we need to access it as math.sqrt(x). Using this dot notation tells Python to use the sqrt function found in the math library module. To calculate the root, you can do discRoot = math.sqrt(b*b – 4*a*c)