Getting Started - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

Getting Started

Description:

Programming is a lot like planning out your morning. Some things are ... 'Funny Math' What is the result of. 31.01 0.01. Where does the extra stuff come ... – PowerPoint PPT presentation

Number of Views:77
Avg rating:3.0/5.0
Slides: 29
Provided by: systema178
Category:
Tags: funny | getting | started | stuff

less

Transcript and Presenter's Notes

Title: Getting Started


1
Getting Started
  • In order, list the tasks you performed this
    morning before you left for campus.

2
Programming is a lot like planning out your
morning
  • Some things are required, others are optional.
  • Certain things must be in the right order while
    other things can be done in any order.
  • Certain tasks are MUCH more involved, but we
    think about them from high view simple terms.
  • Some tasks you assign to other objects.

3
Programming
  • IF, the basic operations of the CPU are those of
    logic, arithmetic, and the rearrangement of
    information in memory
  • AND, software is the appropriate combination of
    these simple operations
  • THEN

4
Question
  • What is the best way write a program?

5
Generations of Programming Languages
  • Generation one (early 1940s to the early 1950's )
    -- machine languages
  • Generation two (early 1950's to the present) --
    assembly language
  • Generation three (middle 1950's to the present)
    -- high-level languages
  • Note Many sources will talk about 4GL and 5GL,
    but they dont fit in to this discussion

6
Machine Language
  • The native tongue of a computer is machine
    language. Everything is represented by a binary
    string of zeros and ones
  • 10110011 00011001
  • 01111010 11010000 110010100
  • 10011111 00011001
  • 01011100 11010001 100100000
  • 10111011 11010001 10010110

7
Machine Language
  • Early computers required the programmer to set
    switches and move wires
  • Which represented a series of 1s and 0s
  • Later computers were programmed using punched
    cards

8
Problems with Machine Language
  • Coding is quite error prone
  • Coding is tedious and slow
  • Code is extremely difficult to modify
  • Code is not portable to a different type of
    computer

9
Assembly Language
  • Assembly language uses Mnemonic symbols to
    represent instructions and data.
  • Programmers write programs using symbolic
    operation codes
  • MV COST, AB
  • MV SHIP, AC
  • ADD AC, AB, AD
  • STO AD, TOTAL

10
Assembly Language
  • To use programs in assembly language
  • Write the code in assembly language
  • Use an assembler to translate to machine language
  • Load and run the machine language version with a
    special program called a loader

11
Problems with Assembly Language
  • While assembly language is a little more
    programmer-friendly
  • Still tedious
  • Still difficult to modify
  • Still not portable

12
High-level languages
  • Designed to be human friendly, easy to write,
    easy to read, and easy to understand.
  • Each instruction corresponds to many instructions
    in machine language.
  • total cost ship

13
High-level Languages
  • To use programs written in a high-level language
    (HLL)
  • Write the code in the HLL (source code)
  • Depending on the language
  • Use a compiler to translate the source to machine
    language (object code)
  • Use an interpreter to simulate a computer that
    understands the HLL and translate each line of
    source into machine language instruction by
    instruction.

14
A compiled language
15
An interpreted language
16
We will use python
  • Python is a high-level programming language first
    released by Guido van Rossum in 1991
  • Python is a multi-paradigm programming language
    (primarily functional, object oriented and
    imperative) which has a fully dynamic type system
    and uses automatic memory management.
  • Python is interpreted, which means you can write
    and execute code dynamically.
  • The language has an open, community-based
    development model managed by the non-profit
    Python Software Foundation.

17
Technically, we will use Jython.
  • Jython, formerly known as JPython, is an
    implementation of the Python programming language
    written in Java.
  • The base Python interpreter is written in C
  • While Jythons interpreter is written in Java
  • The advantage???
  • Because it goes through Java, you can use Javas
    classes

18
What is JES?
  • JES is a free integrated development environment
    for doing python (Jython) programming and
    contains some media manipulation classes not part
    of base Python
  • From Georgia Tech
  • It has several window panes in it
  • For creating programs (definitions pane)
  • For trying out code (interactions pane)

19
Lets work through Labs 1 and 2
  • The rest of class will be somewhat freeform based
    on how things go and what questions you ask. We
    will look at a variety of issues from Labs 1 and
    2 as well as the slides that follow.

20
Number literals
  • By default, JES assumes that anything without a
    decimal is an integer.
  • 2
  • 2
  • -5
  • -5
  • By default, JES assumes that anything with a
    decimal is a floating point number.
  • 3.5
  • 3.5
  • -4.0
  • -4.0

21
Math Operators ( / - )
  • But on their own, number literals are boring.
  • Python, like most languages, provides 6 binary
    mathematical operators
  • Here, binary means two numbers
  • Addition
  • 3 4
  • Multiplication
  • 3 4
  • Division
  • 3 / 4
  • Subtraction
  • 3 4
  • Exponents/powers
  • 3 4
  • Modulo (Remainder)
  • 10 2 and 11 2

22
Math Operators Exercise
  • How would I perform each of the following in JES
    and what would be the answer?
  • Subtract 7 from 9
  • Add 7 to 3
  • Divide 3 by 2
  • Divide 4.6 by 2
  • Multiply 5 by 10
  • Find the remainder when you divide 10 by 3

23
Why is the result of 3 / 2 1?
  • Each value has a type associated with it that
    tells the computer how to interpret the number
  • It is an integer, floating point, letter, etc
  • The interpreter determines the type
  • 3 is an integer
  • 3.0 is a floating point number (has a fractional
    part)
  • The result of an operation is in the same type as
    the operands
  • 3 and 2 are integers so the answer is an integer 1

24
Casting
  • There are other ways to solve the problem of 3 /
    2 has a result of 1
  • You can make one of the values floating point by
    adding .0
  • 3.0 / 2
  • 3 / 2.0
  • The result type will then be floating point
  • Or you can cast one of the values to the
    primitive types float or double
  • float( 3 ) / 2
  • 3 / float( 2 )
  • But not
  • float (3/2)

25
Other Funny Math
  • What is the result of
  • 31.01 0.01
  • Where does the extra stuff come from?

26
Other Funny Math
  • Remember what we talked about in regards to
    encoding decimals
  • 2n 2n-1 2n-2 22 21 20. 2-1 2-2 2-3
    2m-1 2m
  • There are a limited number of places you can
    encode.
  • Any leftovers get ignored which causes problems
    when you de-code

27
Operator Order
  • The default evaluation order is
  • Negation
  • Exponents
  • Multiplication
  • Division /
  • Modulo (remainder)
  • Addition
  • Subtraction -
  • The default order can be changed
  • By using parenthesis
  • (3 4) 2 versus 3 4 2

28
Math Operator Order Exercise
  • What is the result of
  • 2 3 4 5
  • Where would you add parentheses to make it clear
    what is happening first
  • How do you change it so that 2 3 happens first?
  • How do you change it so that it multiplies the
    result of 2 3 and the result of 4 5?
Write a Comment
User Comments (0)
About PowerShow.com