COSC 1306 COMPUTER SCIENCE AND PROGRAMMING

Slides:



Advertisements
Similar presentations
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Advertisements

Objectives In this chapter, you will learn about:
Debugging Introduction to Computing Science and Programming I.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
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.
Compilers and Interpreters. Translation to machine language Every high level language needs to be translated to machine code There are different ways.
Chapter 3 Planning Your Solution
Homework Reading –Finish K&R Chapter 1 (if not done yet) –Start K&R Chapter 2 for next time. Programming Assignments –DON’T USE and string library functions,
Hello AP Computer Science!. What are some of the things that you have used computers for?
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
General Programming Introduction to Computing Science and Programming I.
Errors And How to Handle Them. GIGO There is a saying in computer science: “Garbage in, garbage out.” Is this true, or is it just an excuse for bad programming?
August 29, 2005ICP: Chapter 1: Introduction to Python Programming 1 Introduction to Computer Programming Chapter 1: Introduction to Python Programming.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving  Recognizing Patterns  If you can find a pattern in the way you solve.
BMTRY 789 Lecture 11: Debugging Readings – Chapter 10 (3 rd Ed) from “The Little SAS Book” Lab Problems – None Homework Due – None Final Project Presentations.
Python Conditionals chapter 5
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
ITM © Port, Kazman 1 ITM 352 How to Think Like a Programmer.
The Anatomy of a Computer Program Unit 3. Programs are Directions  A computer carries out the instructions in a program, line by line, exactly as they.
Python Let’s get started!.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
1 CS 1430: Programming in C++. 2 Input: Input ends with -1 Sentinel-Controlled Loop Input: Input begins with.
CSD 340 (Blum)1 For Loops See Beginning JavaScript (Paul Wilton) p. 87.
CSx 4091 – Python Programming Spring 2013 Lecture L2 – Introduction to Python Page 1 Help: To get help, type in the following in the interpreter: Welcome.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Introducing Python 3 Introduction to Python. Introduction to Python L1 Introducing Python 3 Learning Objectives Know what Python is and some of the applications.
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
Chapter 13 Debugging Strategies Learning by debugging.
Few More Math Operators
Introduction to Computing Science and Programming I
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING
Python Let’s get started!.
Introduction to Python
ICS103 Programming in C Lecture 3: Introduction to C (2)
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING
Ruth Anderson UW CSE 160 Winter 2017
Conditions and Ifs BIS1523 – Lecture 8.
Introduction to C++ Programming
Exception Handling.
Chapter 2 - Introduction to C Programming
Escape sequences: Practice using the escape sequences on the code below to see what happens. Try this next code to help you understand the last two sequences.
Types, Truth, and Expressions (Part 2)
Ruth Anderson UW CSE 140 Winter 2014
COMPUTER PROGRAMMING PYTHON
ERRORS AND EXCEPTIONS Errors:
Chapter 2 - Introduction to C Programming
Problem Solving Skill Area 305.1
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
Debugging “Why you were up till 2AM”
Homework Reading Programming Assignments Finish K&R Chapter 1
CHAPTER 6: Control Flow Tools (for and while loops)
An Introduction to Debugging
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
Chapter 2 - Introduction to C Programming
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING
CHAPTER 5: Control Flow Tools (if statement)
Introduction to Computer Science
Chapter 1: Programming Basics, Python History and Program Components
Input and Output Python3 Beginner #3.
1.3.7 High- and low-level languages and their translators
CHAPTER 6 Testing and Debugging.
Types, Truth, and Expressions (Part 2)
Presentation transcript:

COSC 1306 COMPUTER SCIENCE AND PROGRAMMING Jehan-François Pâris jfparis@uh.edu Fall 2017 1

THE ONLINE BOOK CHAPTER II DEBUGGING

Why this chapter? "Programmers spend 80 percent of their time chasing bugs and the remaining 20 percent creating new ones." Certainly true of bad programmers Many beginners become quickly discouraged when their programs do not do what they were supposed to do.

What is a bug? Anything that prevents our programs from doing what they are supposed to do Syntax errors Missing ending quotes, missing closing parentheses, missing columns Poor indentation Semantic error Inconsistent variable naming …

Writing bug-free code Not really possible for most of us Can reduce their number and severity A good approach Start small Write a partial solution to your problem Keep it working Add incremental steps Be sure each new step works before adding another one

Beginning tips Suspect everything but Python Too many users have tested it Could be a wide gap between What your program actually does What you think it does Find clues

Narrowing the gap (I) Insert print statements Anywhere you think there could be a problem print(xyz) or better print("xyz =", xyz) Works for all Python data types When you are done Comment these statements out # print("xyz =", xyz) Do not delete them until you are sure you will not need them

Narrowing the gap (II) Analyze your code Print it on paper if you can Pretend to be the Python interpreter Execute each statement blindly Writing down the results at each step Works best after you have taken a break Repeat the process in front of a friend/TA You can let a friend look at your code but you cannot pass your program to any other student.

A good error message (I) A very short program """ Converts miles into kilometers """ miles = float(input("Enter a mileage: ")) kms = miles*1609.4 print("That's %.2f kilometers" % km)

A good error message (II) The program output Enter a mileage: 100 Traceback (most recent call last): File ".../badconvert.py", line 4, in <module> print("That's %.2f kilometers" % km) NameError: name 'km' is not defined

A good error message (III) What it means """ Converts miles into kilometers """ miles = float(input("Enter a mileage: ")) kms = miles*1609.4 print("That's %.2f kilometers" % km) Misspelled the variable name kms

Another good error message (I) Another error """ Converts miles into kilometers """ miles = float(input("Enter a mileage: ") kms = miles*1609.4 print("That's %.2f kilometers" % kms)

Another good error message (II) Interpreter warns "EOL while parsing string literal" Problem was a missing quote """ Converts miles into kilometers """ miles = float(input("Enter a mileage: ")) kms = miles*1609.4 print("That's %.2f kilometers" % kms)

A confusing error message Another mistake """ Converts miles into kilometers """ miles = float(input("Enter a mileage: ") kms = miles*1609.4 print("That's %.2f kilometers" % kms) Interpreter warns "invalid syntax"

The error A missing closing parenthesis """ Converts miles into kilometers """ miles = float(input("Enter a mileage: ")) kms = miles*1609.4 print("That's %.2f kilometers" % kms)

The key ideas Start small Use print statements whenever there is a doubt Look thoroughly at your code Be persistent

Using functions Let you decompose your program into a series of functions and function calls One of my programs 235 lines of code 12 functions All fairly short