Thanks to: Dr. John S. Mallozzi Department of Computer Science 1. Introduction 2. Overview of programming in Python.

Slides:



Advertisements
Similar presentations
CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
Advertisements

1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
Lab6 – Debug Assembly Language Lab
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming The software development method algorithms.
Python Programming Chapter 1: The way of the program Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
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
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
Guide To UNIX Using Linux Third Edition
Programming. Software is made by programmers Computers need all kinds of software, from operating systems to applications People learn how to tell the.
CHAPTER 1: INTORDUCTION TO C LANGUAGE
Computer Science 101 Introduction to Programming.
Programming In C++ Spring Semester 2013 Programming In C++, Lecture 1.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
1 Integrated Development Environment Building Your First Project (A Step-By-Step Approach)
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
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.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
Introduction to Computers and Programming – Computer Programming.
CS161 Topic #21 CS161 Introduction to Computer Science Topic #2.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 1 Introduction to Computers and Programming.
Introduction to Programming Peggy Batchelor.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Computer Science 101 Introduction to Programming.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions.
Input, Output, and Processing
Python – Part 1 Python Programming Language 1. What is Python? High-level language Interpreted – easy to test and use interactively Object-oriented Open-source.
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
Python From the book “Think Python”
Just as there are many human languages, there are many computer programming languages that can be used to develop software. Some are named after people,
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
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.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Introduction to Python Lesson 1 First Program. Learning Outcomes In this lesson the student will: 1.Learn some important facts about PC’s 2.Learn how.
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.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015.
CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington.
The single most important skill for a computer programmer is problem solving Problem solving means the ability to formulate problems, think creatively.
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
INTRODUCTION TO COMPUTER PROGRAMMING(IT-303) Basics.
Getting Started With Python Brendan Routledge
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Software Engineering Algorithms, Compilers, & Lifecycle.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
Software Development Languages and Environments. Computer Languages Just as there are many human languages, there are many computer programming languages.
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
Chapter 1 Introduction 2nd Semester H
Development Environment
A Playful Introduction to Programming by Jason R. Briggs
Topics Introduction Hardware and Software How Computers Store Data
Guide To UNIX Using Linux Third Edition
String Output ICS 111: Introduction to Computer Science I
Topics Introduction Hardware and Software How Computers Store Data
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Programming.
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Chapter 1: Programming Basics, Python History and Program Components
1.3.7 High- and low-level languages and their translators
Week 1 - Friday COMP 1600.
Presentation transcript:

Thanks to: Dr. John S. Mallozzi Department of Computer Science 1. Introduction 2. Overview of programming in Python

2 Program – a set of instructions that allows a computer to perform a task When a program is used to make the computer perform a task, the program is executed Gives a computer its flexibility  Change the program; change the task that can be performed Programs can be used by anyone Programs must be written by specially trained and educated people – programmers

3 A computer is an electronic device – it doesn’t “understand” any language Communication is by electronic switches (on-off) Switch positions can be represented by (encoded using) the digits 1 (on) and 0 (off)  Two positions, so called binary code  Recall: bit sequences can be written using hexadecimal Binary code is also called machine language  This is the only language “understood” by a computer

4 Working in machine language is extremely tedious and error-prone for humans Easier-to-use languages were developed  Low-level languages are like machine language, but allow the use of labels instead of binary codes  High-level languages are closer to spoken languages, although without ambiguity and much more limited A program written in such a language must be translated into machine language Only machine-language can be executed

5 More like ordinary spoken language, but inflexible and unambiguous Much easier for programmers to use than low-level languages (assembly) or machine language One statement generally corresponds to many internal computer instructions

6 A popular high-level, interpreted language, which is reasonably easy to learn Has form close enough to English to be much easier to use than low-level languages Is simpler in form than many other high-level languages, such as Java or C++ Is available as a free download Comes with many online resources  Help  Tutorials and References  Modules – libraries of pre-written solutions

7 Python is a free download, and is easy to install and set up if you want to. You can always use Lab computers. Instructions are available in textbooks (optional) and online. If you are going to install Python you can use the instructions available at the following link:

IDLE - Immediate Mode A programmer’s editor and execution shell that comes with Python (be sure to use “Idle Basic” in the labs.) 8 For many applications, You must be sure that You see this before you start

9 Python’s immediate mode, as seen in Idle, can be used like a calculator  You enter an expression at the prompt: >>>  After you press enter/return, the expression you entered is evaluated, and the result is printed (in a distinct color) on the next line Unlike a calculator, Python’s immediate mode allows much more, such as use of names for results and program steps, manipulation of text, etc. Example of use:

10 Immediate mode allows you to do anything of which the computer is capable This allows you to “try out” different ideas about solving a problem Once you have the idea, you can write a program, so that the method you have come up with can be saved to be used and reused

11 Here is a mathematical formula:  In words: to add the integers from 1 up to some positive integer, multiply that integer by the next integer, then take half the result You cannot use a computer to prove this, but you can use it to help you believe it We will use some Python features in this example, but don’t worry about them (we’ll get to all eventually)—just focus on how we are using the computer

12 Features of Python we will use:  range, followed by two integers in parentheses, gives you a list of the integers from the first integer to one less than the second one  Example: range(1,10 ) is [1,2,3,4,5,6,7,8,9]  To add all the numbers on a list, use sum  To multiply, use * and to divide use /

13 Creating a file Saving the file Entering a program Translating and executing the program Testing and error correction Three Rules Of Programming:  1) THINK before you program  2) A program is a human-readable essay on problem solving that also executes on a computer.  3) The best way to improve programming and problem- solving skills is to Practice, Practice, Practice.  4) THINK before and WHILE you program

14 Once you have a series of commands that perform a desired task, you can save them as a program From the Idle menu, choose New Window

15 Before doing anything else, add your full heading at the top of the file in a comment, and save the file Use your U drive! Must add the.py extension to the file name. Not automatic!  If you don’t, text color will no longer show

16

17 Once the file has been saved, you can enter Python commands or statements Learning the commands available will take some effort, but not nearly as much as for a spoken language For now, enter the traditional first program: print (“Hello World”) Add another output statement with a custom greeting of your own choosing.

18 Save the file to preserve the changes Use the Run menu, and choose Run Module (If you have not saved, will prompt to save)  You will be returned to the Shell, and your program will be executed

19 If you entered the program incorrectly, you will get an error message instead In that case, return to the editing window, fix the program, and repeat the execution steps

20 There are three main kinds of errors  Typos (Precision!) IDLE editor can help spot and fix these  Incorrect Python  Solution: find out how to do it correctly, then change the program and try again  Correct Python, but incorrect results  Solution: carefully think again about what you wanted, and be sure you used the right Python commands, in the right order The second kind of error is frustrating at first, but eventually becomes easy to fix The third kind is called a bug, and may cause a lot of trouble – best is to avoid these by being careful about your planning and logic from the start

21 Designing with algorithms Idea of an algorithm Example Computational example Another way – Turtle Graphics

22 The best language in which to plan is your own native, spoken language – result is an algorithm Once the plan is done, you can convert it to a program – implementation of the algorithm Another way to approach a problem is the use of prototyping Combining the two ideas, designing an algorithm and prototyping, can lead to a successful program to solve a problem Key to all this is knowing what a computer can do and how to express the commands to make it do so

23 An algorithm is a step-by-step description of how to complete a task  Idea is to carefully specify all steps – do not expect listener/reader/computer to fill in details  Example: This is not an algorithm To get to my house turn left twice, then slight right, then right, and then into driveway  Humans are good at leaving out steps  Computers are terrible at filling in missing steps A program is an algorithm (or several algorithms) that has been implemented – translated into a computer language

24 Problem – Shopping: drive to bank, get money, then drive to a store to buy bread, then drive home Algorithm:  Drive to bank  Go into bank  Get money out of bank  Drive to store  Go into store  Buy bread  Drive home Too much detail for a human, still too little for a computer

25 Problem: Draw the letter ‘E’ on the screen by using stars (asterisks):  Solution: (keeping in mind that printing is done left-to- right, top-to-bottom)  Print top horizontal segment  Print first short vertical segment  Print middle horizontal segment  Print second short vertical segment  Print bottom horizontal segment

26 Translation is easy using English! Do this, but in comments Fill in details later Result is the “skeleton” of a program, which records the algorithm in comments

27 To draw a horizontal segment, print a number of stars ( Use 7 for now) on a single line To draw a vertical segment, print a single star on each of a number (we’ll use 3) of lines

28 Computers are capable of graphics, allowing a more “natural” way to make a letter E Python comes with Turtle Graphics Idea is to use angles and distances to move a “turtle” which draws as it moves Lab is the place for detail; for now we do just enough to draw letter E The algorithm is the same, but now we think of drawing the letter without lifting the pen from the paper (there are other ways, of course) We need only a few turtle commands to do this

29 We must get the Turtle Graphics library—this is done by importing it  We ask for everything in the library using * for the name of what to import: from turtle import * We need the commands forward, back, right, and left We also use the hideturtle() command so that all we see is the drawing

30