CIT 590 Intro to Programming Lecture 3. Pair programming logistics You and your partner submit 1 assignment Figure out who the submitter will be PLEASE.

Slides:



Advertisements
Similar presentations
Basics of Recursion Programming with Recursion
Advertisements

More on Psuedo-Code Sangeetha Parthasarathy 1/23/01.
22C:19 Discrete Structures Induction and Recursion Spring 2014 Sukumar Ghosh.
22C:19 Discrete Structures Induction and Recursion Fall 2014 Sukumar Ghosh.
We Have Learned main() { … } Variable –Definition –Calculation –Display We can do some real programming! –Think about your solution design –Express design.
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Why care about debugging? How many of you have written a program that worked perfectly the first time? No one (including me!) writes a program that works.
Recursion in Python. Recursion Problems in every area of life can be defined recursively, that is, they can be described in terms of themselves. An English.
Lecture 27 Exceptions COMP1681 / SE15 Introduction to Programming.
1 Chapter 11 l Basics of Recursion l Programming with Recursion Recursion.
Scott Grissom, copyright 2004 Chapter 5 Slide 1 Analysis of Algorithms (Ch 5) Chapter 5 focuses on: algorithm analysis searching algorithms sorting algorithms.
1 Chapter 18 Recursion Dale/Weems/Headington. 2 Chapter 18 Topics l Meaning of Recursion l Base Case and General Case in Recursive Function Definitions.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Functions Outline 3.12Recursion 3.13Example Using Recursion: The Fibonacci Series 3.14Recursion.
CIT 590 Debugging. Find a laptop Please take a moment to open up your laptop and open up Eclipse. If you do not have a laptop, please find a friend. If.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
DEBUGGERS For CS302 Data Structures Course Slides prepared by TALHA OZ (most of the text is from
 2000 Prentice Hall, Inc. All rights reserved. Chapter 5 – Recursive Funtions From Deitel’s “C” Book 5.13Recursion 5.14Example Using Recursion: The Fibonacci.
Study Tips for COP 4531 Ashok Srinivasan Computer Science, Florida State University Aim: To suggest learning techniques that will help you do well in this.
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Recursion Review.
Programming in C++ Language ( ) Lecture 6: Functions-Part2 Dr. Lubna Badri.
C++ Beginner Tutorial: Functions IV Recursion. What is recursion? A property of function to be able to call itself… Get factorial of a given number: Factorial.
DEBUGGING CHAPTER Topics  Getting Started with Debugging  Types of Bugs –Compile-Time Bugs –Bugs Attaching Scripts –Runtime Errors  Stepping.
ICAPRG301A Week 4Buggy Programming ICAPRG301A Apply introductory programming techniques Program Bugs US Navy Admiral Grace Hopper is often credited with.
CIT 590 Examples Debugging. Agenda This class is an experiment in letting students learn by just doing things as opposed to me talking all the time! So.
CHAPTER 02 Recursion Compiled by: Dr. Mohammad Omar Alhawarat.
Lecture 10 Recursion CSE225: Data Structures. 2 A Look Back at Functions #include double distance(double x1, double y1, double x2, double y2) { double.
Fall Week 3 CSCI-141 Scott C. Johnson.  Say we want to draw the following figure ◦ How would we go about doing this?
Chapter 11Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 11 l Basics of Recursion l Programming with Recursion Recursion.
Recursion Self-Referencing Functions. Problem # 1 Write a function that, given n, computes n! n! == (n-1) n n! == 1  2 ...  (n-1)  nExample:
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Review Introduction to Searching External and Internal Searching Types of Searching Linear or sequential search Binary Search Algorithms for Linear Search.
Debugging in Java. Common Bugs Compilation or syntactical errors are the first that you will encounter and the easiest to debug They are usually the result.
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.
Cosc175/testing1 Testing Software errors are costly GIGO Preventing Errors –Echo checking –Range and limit checking –Defensive programming.
 2007 Pearson Education, Inc. All rights reserved C Functions -Continue…-
Recursion. What is recursion? Rules of recursion Mathematical induction The Fibonacci sequence Summary Outline.
Data Structures R e c u r s i o n. Recursive Thinking Recursion is a problem-solving approach that can be used to generate simple solutions to certain.
Recursion Review: A recursive function calls itself, but with a smaller problem – at least one of the parameters must decrease. The function uses the results.
CS101 Computer Programming I Chapter 4 Extra Examples.
Chapter 12. Recursion Basics of Recursion Programming with Recursion Computer Programming with JAVA.
CSE 351 GDB Introduction. Lab 1 Status? How is Lab 1 going? I’ll be available at the end of class to answer questions There are office hours later today.
Debuggers in Python. The Debugger Every programming IDE has a tool called a debugger. This application does NOT locate or fix your bugs for you! It slows.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
11. EXCEPTION HANDLING Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
Recursion A recursive definition is one which uses the word or concept being defined in the definition itself Example: “A computer is a machine.
W1-1 University of Washington Computer Programming I Recursion © 2000 UW CSE.
While loops. Iteration We’ve seen many places where repetition is necessary in a problem. We’ve been using the for loop for that purpose For loops are.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
Python – Part 4 Conditionals and Recursion. Conditional execution If statement if x>0:# CONDITION print (‘x is positive’) Same structure as function definition.
Recursion Function calling itself
Recursion Recursion is a fundamental programming technique that can provide an elegant solution certain kinds of problems © 2004 Pearson Addison-Wesley.
RECURSION.
Module 3.
Testing and Debugging.
Java 4/4/2017 Recursion.
Chapter 9 Recursion.
Important Notes Remaining Schedule: recall the 2 bad weather days (Jan 8th, Jan 17th) we will need to make up. In providing the 2 weeks needed for the.
DEBUGGING JAVA PROGRAMS USING ECLIPSE DEBUGGER
Intro to Programming Lecture 3
Structured Programming Taken from notes by Dr. Neil Moore
Debugging at Scale.
Using a Debugger 1-Jan-19.
Recursion (part 1) October 24, 2007 ComS 207: Programming I (in Java)
Recursion Taken from notes by Dr. Neil Moore
Self-Referencing Functions
Recursion.
IST256 : Applications Programming for Information Systems
CIS 110: Introduction to Computer Programming
Presentation transcript:

CIT 590 Intro to Programming Lecture 3

Pair programming logistics You and your partner submit 1 assignment Figure out who the submitter will be PLEASE write the name of you and your partner. I wish I could write a filter that rejects submissions that do not have this … You and your partner get the same grade Your partner this week will not be your partner next week

Pair programming pdf pdf

Agenda Recursion Throwing exceptions Functions returning nothing Debugging

Recursion A function calling itself Factorial def factorial(n): if n == 0: return 1 return n * factorial(n-1) numToString example from the book

Recursion pitfall Not having a base case Errors out very much like an infinite loop If you have seen mathematical induction This about the base case as the first step of induction Always always write the base case first. After all, it is supposed to be the easy case, so let’s do that first

Recursion pitfall number 2 Doing fibonacci with and without recursion How many recursive calls is fibonacci making 2 for each call … and this summation is increasing exponentially In this case an alternate solution is easy. (iterativeFibonacci.py)

Agenda Recursion Throwing exceptions Functions returning nothing Debugging

Exceptions Handling unexpected situations Halt the execution so that the potential error does not propagate and cause an even bigger one ‘defensive programming’ Example – romanToDecimalConversion.py

Agenda Recursion Throwing exceptions Functions returning nothing Debugging

Functions that return nothing The NoneType used fairly often to initialize the value of a variable when you do not know what it might eventually hold

Agenda Recursion Throwing exceptions Functions returning nothing Debugging

Software is full of bugs! Murphy’s law adapted to Software Engineering says Every non trivial program has at least one bug Corollary 1 - A sufficient condition for program triviality is that it have no bugs. Corollary 2 - At least one bug will be observed after the author leaves the organization How do we figure out what is going on?

Debugging Old school print statements Never underestimate the power of dumping information Take out your log statements before submitting code Else you will be publicly shamed …or worse

IDLE debugger Breakpoints Stepping into and over Go starts the program. It runs until it hits another breakpoint, waits for keyboard input, or the program ends. Step executes the next statement. If it is the breakpointed statement, that statement is executed. If the statement is a function call (as this one is), the debugger enters the called function Over executes the next statement as step does, but does stay in the current code. It does not enter any functions. Out exits the function that it is in, returning control to the caller. Quit ends the program

Summary Recursion Throwing exceptions IDLE debugger