General Computer Science for Engineers CISC 106 Lecture 03

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions.
Advertisements

CS 100: Roadmap to Computing Fall 2014 Lecture 0.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
Introduction to a Programming Environment
Hello, world! Dissect HelloWorld.java Compile it Run it.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
PYTHON: LESSON 1 Catherine and Annie. WHAT IS PYTHON ANYWAY?  Python is a programming language.  But what’s a programming language?  It’s a language.
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
Computer Science 101 Introduction to Programming.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
Topics Introduction Hardware and Software How Computers Store Data
Introduction to Python
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 1 Introduction to Computers and Programming.
PYTHON. Python is a high-level, interpreted, interactive and object- oriented scripting language. Python was designed to be highly readable which uses.
Introduction to Programming Peggy Batchelor.
Programming in Python Part I Dr. Fatma Cemile Serçe Atılım University
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Computer Science 101 Introduction to Programming.
General Computer Science for Engineers CISC 106 Lecture 04 Dr. John Cavazos Computer and Information Sciences 09/10/2010.
Lecture #5 Introduction to C++
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 1 Introduction.
I Power Higher Computing Software Development Development Languages and Environments.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
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.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
Python Basics  Values, Types, Variables, Expressions  Assignments  I/O  Control Structures.
Machine Language Computer languages cannot be directly interpreted by the computer – they are not in binary. All commands need to be translated into binary.
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
Input, Output and Variables GCSE Computer Science – Python.
Fundamentals of Programming I Overview of Programming
UMBC CMSC 104 – Section 01, Fall 2016
Programming what is C++
Agenda Introduction Computer Programs Python Variables Assignment
A Python Tour: Just a Brief Introduction
Python: Experiencing IDLE, writing simple programs
Chapter 5- Assembling , Linking, and Executing Programs
Chapter 1: Introduction to computers and C++ Programming
CSC201: Computer Programming
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Topics Introduction Hardware and Software How Computers Store Data
Introduction to Python
Topics Introduction to Repetition Structures
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Variables, Expressions, and IO
Introduction to C Topics Compilation Using the gcc Compiler
Chapter 1 Introduction to Computers and Programming
Assembler, Compiler, Interpreter
and Executing Programs
CS190/295 Programming in Python for Life Sciences: Lecture 1
Topics Introduction Hardware and Software How Computers Store Data
Topics Introduction Hardware and Software How Computers Store Data
Topics Designing a Program Input, Processing, and Output
Assembler, Compiler, Interpreter
PROGRAMMING FUNDAMENTALS Lecture # 03. Programming Language A Programming language used to write computer programs. Its mean of communication between.
12th Computer Science – Unit 5
Chapter 1: Programming Basics, Python History and Program Components
Programming for Business Computing Introduction
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

General Computer Science for Engineers CISC 106 Lecture 03 Dr. John Cavazos Computer and Information Sciences 09/07/2010

Machine Language to Assembly Computers only understand machine language Machine language is difficult to write Assembly language uses short words that are known as mnemonics Assembler is used to translate an assembly language program to machine language Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Do you know of any other high-level computer programming languages? High-Level Languages Assembly language is referred to as a low-level language High-level languages allow you to create powerful and complex programs without knowing how the CPU works, using words that are easy to understand. For example: Ada, BASIC, Python, C++, Ruby, Visual Basic Do you know of any other high-level computer programming languages? Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Compilers and Interpreters The statements written in a high-level language are called source code or simply code Source code is translated to machine language using a compiler or an interpreter Syntax error is a mistake that the compiler / interpreter can catch: Misspelled word Missing punctuation character Incorrect use of an operator Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Compilers Compiler is a program that translates a high-level language program into a separate machine language program Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Interpreter An interpreter is a program that both translates and executes the instructions in a high-level language program Python language uses an interpreter Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Python Introduction Python programs can be saved in files Python interpreter : Can run programs Can execute individual statements typed at prompt IDLE is a development environment Can be used to write, execute, and test Python programs Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Python Interpreter A program that can read Python programming statements and execute them is the Python interpreter Python interpreter has two modes: Interactive mode waits for a statement from the keyboard and executes it Script mode reads the contents of a file (Python program or Python script) and interprets each statement in the file Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Python Interpreter (cont’d) Interpreter Mode Invoke Python interpreter >>> is prompt indicating interpreter is waiting for a Python statement >>> print ‘Python programming is fun!’ Python programming is fun! >>> Statements typed in interactive mode are not saved as a program [ENTER] Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Python Interpreter (cont’d) Script Mode Use a text editor to create a file containing the Python statements Save the file with a .py extension Run the program: > python test.py [ENTER] Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

What is a function? inputs output

Designing Programs Use Design Recipes 5 Steps TAs will make sure you follow steps!

Design Recipe : Step 1 : Docstring Read the problem. Inputs : What kinds of data does the function consume? Output : What kind of data does it produce? Write a short purpose statement. List all required input parameters (use meaningful names). Provide data kinds for each parameter, including the return value.

Design Recipe : Step 1 (example) Write a function that computes the area of a rectangle, given the width and height.

Design Recipe : Step 2 : Function Header Write the function header, using the information from the contract. def area(width, height): inputs keyword function name

Design Recipe : Step 3 : Testing Make up examples of inputs. What should your program produce for those inputs? Write these as unit tests using assertEqual. assertEqual(area(0,0), 0) assertEqual(area(10,10), 100)

Design Recipe : Step 4 : Function Body Now write your function body. Look closely at your examples, and try to see the pattern. How can the inputs be turned into the desired outputs? def area(width, height): … return width * height

Design Recipe : Step 5 : Put it all Together! Now put it all together into one Python file,

Extra Slides

Atomic Data - Numbers : floats, integers Can use “type” to find out the data type of something. type(5) # int type (5.0) # float Strings Some examples : “hello” and ‘hello’ type(“hello”) # str “hello” + “world” # plus symbol concatenates two strings

Atomic Data (cont’d) Booleans True False True and False True or False type(True) # bool

Atomic Data (cont’d) # Can mix and match numbers >>> 3 + 5.0 8.0 # Cannot mix numbers and strings “hello” + 3 # Builtin convert between types str(100) int(“5”)

Programming, Computing, Functions Programming = writing “arithmetic” expressions Computing = finding the value of an expression Functions = programs that take inputs and compute outputs

Simple Function What is the expression being computed? X= 1 2 3 4 5 Y= 9 16 ??

Simple Function The python function to compute this table. def compute_square(x) : """ returns the square of the input value x that is passed in x -- int return – int return x * x X= 1 2 3 4 5 Y= 9 16 ??