Introduction to Problem Solving and Programming in Python.

Similar documents
Lecture 27. Lecture 27: Regular Expressions and Python Identifiers

Getting Started with Python

Fundamentals of Programming (Python) Getting Started with Programming

Basic Syntax - First Program 1

Chapter 15 Debugging

Program Correctness and Efficiency. Chapter 2

CSCA08 Winter Week 12: Exceptions & Testing. Marzieh Ahmadzadeh, Brian Harrington University of Toronto Scarborough

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

Chapter 2 Writing Simple Programs

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

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

CHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS

Agile development. Agile development work cycle. Reacting to bugs

CMSC 201 Computer Science I for Majors

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

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

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

Introduction to Programming

Table of Contents EVALUATION COPY

Testing. ECE/CS 5780/6780: Embedded System Design. Why is testing so hard? Why do testing?

STEAM Clown & Productions Copyright 2017 STEAM Clown. Page 1

c. Typically results in an intractably large set of test cases even for small programs

Variable and Data Type I

PROGRAMMING FUNDAMENTALS

Lecture 01 & 02 Computer Programming

SI Networked Computing: Storage, Communication, and Processing, Winter 2009

Chapter 9: Dealing with Errors

About Variables in Python F E B 1 1 T H

4. The is a diagram that graphically depicts the steps that take place in a program. a. Program b. Flowchart c. Algorithm d. Code e.

Variable and Data Type I

Programming with Python

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

11Debugging and Handling. C# Programming: From Problem Analysis to Program Design 2nd Edition. David McDonald, Ph.D. Director of Emerging Technologies

SECTION 5: STRUCTURED PROGRAMMING IN MATLAB. ENGR 112 Introduction to Engineering Computing

Introduction to Dynamic Analysis

Variables, expressions and statements

Jython. secondary. memory

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Computer Science 217

Python Tutorial. CS/CME/BioE/Biophys/BMI 279 Oct. 17, 2017 Rishi Bedi

Main concepts to be covered. Testing and Debugging. Code snippet of the day. Results. Testing Debugging Test automation Writing for maintainability

VB Net Debugging (Console)

THE JAVA FOR STATEMENT

Debugging and testing

PREPARING FOR PRELIM 1

In this Lecture you will Learn: Testing in Software Development Process. What is Software Testing. Static Testing vs.

Verification and Validation

Course Content. Objectives of Lecture 18 Black box testing and planned debugging. Outline of Lecture 18

Topics in Software Testing

Lecture 9: GUI and debugging

COMP1730/COMP6730 Programming for Scientists. Testing and Debugging.

Testing and Debugging C Programming and Software Tools. N.C. State Department of Computer Science

18-642: Unit Testing 1/31/ Philip Koopman

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

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

ENGR 101 Engineering Design Workshop

CSE 403: Software Engineering, Fall courses.cs.washington.edu/courses/cse403/16au/ Unit Testing. Emina Torlak

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

Motivations. Chapter 3: Selections and Conditionals. Relational Operators 8/31/18. Objectives. Problem: A Simple Math Learning Tool

CS 1301 CS1 with Robots Summer 2007 Exam 1

CMSC 330: Organization of Programming Languages. OCaml Expressions and Functions

Getting started 7. Saving data 23

TABLE OF CONTENTS 2 CHAPTER 1 3 CHAPTER 2 4 CHAPTER 3 5 CHAPTER 4. Algorithm Design & Problem Solving. Data Representation.

CSCI Object Oriented Design: Java Review Errors George Blankenship. Java Review - Errors George Blankenship 1

CSCI Object-Oriented Design. Java Review Topics. Program Errors. George Blankenship 1. Java Review Errors George Blankenship

Bisection Debugging. 1 Introduction. Thomas Gross. Carnegie Mellon University. Preliminary version

Conditionals and Recursion. Python Part 4

Debugging & Errors Why you were up till 2AM

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

And Parallelism. Parallelism in Prolog. OR Parallelism

Unit Testing In Python

Coding Tools. (Lectures on High-performance Computing for Economists VI) Jesús Fernández-Villaverde 1 and Pablo Guerrón 2 March 25, 2018

Unit Tests. # Store the result of a boolean expression in a variable. >>> result = str(5)=='5'

Overview of the Ruby Language. By Ron Haley

Unit Testing as Hypothesis Testing

Darshan Institute of Engineering & Technology for Diploma Studies

Who Am I? Objective. Debugging Essentials

COMP1730/COMP6730 Programming for Scientists. Exceptions and exception handling

CSCE 110 Programming I

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

Chapter 9. Introduction to High-Level Language Programming. INVITATION TO Computer Science

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

Errors. And How to Handle Them

INTRODUCTION TO SOFTWARE ENGINEERING

Unit Testing as Hypothesis Testing

Testing. Prof. Clarkson Fall Today s music: Wrecking Ball by Miley Cyrus

Verification Overview Testing Theory and Principles Testing in Practice. Verification. Miaoqing Huang University of Arkansas 1 / 80

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Using the code to measure test adequacy (and derive test cases) Structural Testing

Assembly Language Fundamentals

2.8. Decision Making: Equality and Relational Operators

Supplement: Visual C++ Debugging

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

TOS Test Center (TTC)

1 Getting used to Python

Test Automation. 20 December 2017

Debugging and Handling Exceptions

Functions and Recursion

Control of Flow. There are several Python expressions that control the flow of a program. All of them make use of Boolean conditional tests.

The role of semantic analysis in a compiler

Transcription:

Introduction to Problem Solving and Programming in Python http://cis-linux1.temple.edu/~tuf80213/courses/temple/cis1051/

Overview Types of errors Testing methods Debugging in Python 2

Errors An error in a program is called a bug The process of finding and removing bugs is called debugging There are 3 kinds of errors in programming Syntax errors Runtime errors Logical errors 3

Syntax Errors Arise from grammatical mistakes in your program When the code written does not follow the syntactical rules of the language (Relatively) Easy to find and fix Immediately caught when the offending line is interpreted (or compiled) Many times reported by your IDE Example using a semicolon where you should use a comma 4

Syntax errors: incorrect names Names in Python (variables, functions) have rules for naming Valid characters are: A-Z a-z 0-9 _ Cannot begin with a number Cannot use a Python keyword (reserved word) 5

Python Keywords False None True and as assert break class continue def del elif else except finally for from global if import in is lambda nonlocal not or pass raise return try while with yield 6

Runtime Errors An error that is detected while the program is running. Caused by a statement that cannot be executed. Causes the program to terminate (Crash) Example dividing by zero 7

Logical Errors An error that is detected while the program is running. Semantic error. The program continues to run, but causes incorrect results Example average = a + b / 2 8

Required debugging effort Syntax error - Fixed before anyone even notices Runtime error - Inconvenient, but we can find and fix Logical error - Can be measured in hair pulled 9

Debugging The process of finding and removing errors in code Takes place when a bug is found (not proactive) Bugs can be found/triggered through Testing 10

Testing A process to show that the software runs as expected Can be manual or automated process Code is run with test cases Predetermined set of inputs with known results Tests are grouped (e.g. boundary testing checking the edge cases of valid input) 11

Testing cont. Testing can prove that a program has bugs, but it cannot prove that a program is bug-free Testing all possible inputs under all possible conditions is infeasible at best, impossible at worst e.g. A program that calculates daily loan interest payments Programmer uses 365 (days) as base of calculation Program is tested in a non-leap year against expected results and are correct During leap year, calculations are incorrect 12

Types of testing Black box System details are hidden White box Internal logic is visible tests code coverage, etc. Unit Test individual components or modules 13

Types of testing cont. Integration Tests if various components work together System Tests entire system (every combined portion) Regression Testing the entire application if a single component is changed Acceptance Performed by the customer. Ensures the application meets specifications. 14

Testing and debugging in Python Tracing Assert Debuggers 15

Tracing The process of recording the program s state after each statement is executed Involves keeping track of variables through various assignments Often times, variable values are printed to the screen to check their values Be sure to remove these print statements when debugging is complete 16

The assert keyword An assertion is a statement to Python that a particular condition should be true at this point in the program Useful in preventing logical errors Syntax: assert condition[, expression] e.g.: assert balance - withdrawal_amount >= 0 balance -= withdrawal_amount 17

The Python debugger pdb (Python DeBugger) is an interactive source code debugger for Python It support breakpoints and single stepping inspecting variable values source code listing executing arbitrary code in context 18

Using pdb 1. Add the following line of code at the beginning of your program import pdb 2. Place pdb.set_trace() At the location where you would like tracing to begin 3. Run your program from the command line PROMPT> python my_program.py 19

Using IDE debugger 1. Some IDEs come with their own debugger 2. May be more intuitive (e.g. GUI interface) 3. May not play well with pdb. Use one or the other. 20