Python – May 17 Recap lab Multidimensional list Exceptions Commitment: quiz tomorrow.

Slides:



Advertisements
Similar presentations
 Computer Science 1MD3 Introduction to Programming Winter 2014.
Advertisements

1 Lecture 11 Interfaces and Exception Handling from Chapters 9 and 10.
Lecture 27 Exceptions COMP1681 / SE15 Introduction to Programming.
Nov 10, Fall 2006IAT 8001 Debugging. Nov 10, Fall 2006IAT 8002 How do I know my program is broken?  Compiler Errors –easy to fix!  Runtime Exceptions.
Python (yay!) November 16, Unit 7. Recap We can store values in variables using an assignment statement >>>x = We can get input from the user using.
Chapter 2 Writing Simple Programs
Exception Error handling. Exception 4 n An unusual occurrence during program execution that requires immediate handling n Errors are the most common type.
Debugging Logic Errors CPS120 Introduction to Computer Science Lecture 6.
Python Control of Flow.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 19 Handling Exceptions 6/09/09 Python Mini-Course: Lesson 19 1.
WEEK EXCEPTION HANDLING. Syntax Errors Syntax errors, also known as parsing errors, are perhaps the most common kind of complaint you get while.
November 15, 2005ICP: Chapter 7: Files and Exceptions 1 Introduction to Computer Programming Chapter 7: Files and Exceptions Michael Scherger Department.
17. Python Exceptions Handling Python provides two very important features to handle any unexpected error in your Python programs and to add debugging.
Exceptions 2 COMPSCI 105 S Principles of Computer Science.
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
Python – May 11 Briefing Course overview Introduction to the language Lab.
Dealing with Errors. Error Types Syntax Errors Runtime Errors Logical Errors.
If statements while loop for loop
Chapter 24 Exception CSC1310 Fall Exceptions Exceptions Exceptions are events that can modify the flow or control through a program. They are automatically.
C++ crash course Class 8 statements, sort, flight times program.
Review, Pseudocode, Flow Charting, and Storyboarding.
FT228/3 Web Development Error processing. Introduction READ Chapter 9 of Java Server Pages from O’reilly 2 nd Edition Need to be able to 1) Diagnose and.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 8 Lists and Tuples.
CHAPTER 3 Decisions and Repetition. A few new constants Constants so far:  Strings  Numbers  integer  float Boolean constants: [On board]
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
Exceptions CMSC 201. Overview Exceptions are run-time errors, especially ones that the programmer cannot predict.  example 1: division by zero  example.
11. EXCEPTION HANDLING Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
Python – May 16 Recap lab Simple string tokenizing Random numbers Tomorrow: –multidimensional array (list of list) –Exceptions.
CS 127 Exceptions and Decision Structures. Exception Handling This concept was created to allow a programmer to write code that catches and deals with.
Exceptions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
LISTS and TUPLES. Topics Sequences Introduction to Lists List Slicing Finding Items in Lists with the in Operator List Methods and Useful Built-in Functions.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Unit – 3 Control structures. Condition Statements 1.If.…..else :- Has someone ever told you, "if you work hard, then you will succeed"? And what happens.
 See pages 65 – 67 in your book  While loops are all around us ◦ Shampoo  Rinse, Lather, Repeat  While (Condition Is True) : ◦ Execute a block of.
 Python for-statements can be treated the same as for-each loops in Java Syntax: for variable in listOrstring: body statements Example) x = "string"
1 Handling Errors and Exceptions Chapter 6. 2 Objectives You will be able to: 1. Use the try, catch, and finally statements to handle exceptions. 2. Raise.
EXCEPTIONS. Catching exceptions Whenever a runtime error occurs, it create an exception object. The program stops running at this point and Python prints.
Loop Control อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 8.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
PH2150 Scientific Computing Skills Control Structures in Python In general, statements are executed sequentially, top to bottom. There are many instances.
Python: Exception Handling Damian Gordon. Exception Handling When an error occurs in a program that causes the program to crash, we call that an “exception”
Chapter 2 Writing Simple Programs
Exceptions in Python Error Handling.
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Example: Vehicles What attributes do objects of Sedan have?
Introduction to Python
Repetition Structures Chapter 9
Selection and Python Syntax
Taken from notes by Dr. Neil Moore & Dr. Debby Keen
Warm-up Program Use the same method as your first fortune cookie project and write a program that reads in a string from the user and, at random, will.
Exceptions and files Taken from notes by Dr. Neil Moore
Python’s Errors and Exceptions
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
Exceptions and files Taken from notes by Dr. Neil Moore
CISC101 Reminders Assn 3 due tomorrow, 7pm.
ERRORS AND EXCEPTIONS Errors:
Exceptions.
Topics Sequences Introduction to Lists List Slicing
Problems Debugging is fine and dandy, but remember we divided problems into compile-time problems and runtime problems? Debugging only copes with the former.
Advanced Python Concepts: Exceptions
Topics Sequences Lists Copying Lists Processing Lists
Program Flow.
Advanced Python Concepts: Exceptions
Introduction to Computer Science
Topics Sequences Introduction to Lists List Slicing
Exception Handling COSC 1323.
CISC101 Reminders Assignment 3 due today.
How to allow the program to know when to stop a loop.
Presentation transcript:

Python – May 17 Recap lab Multidimensional list Exceptions Commitment: quiz tomorrow

Lab notes Put delimiters inside (“[ ]”) When you sort a list, there is no return value L.sort()# rather than L = L.sort() In lottery problem, how did you make sure all winning numbers distinct? –Technique also helpful when “dealing” cards. Can check syntax before running: next to run button there is a “check”. Status bar shows result, and cursor taken to error, if any

Multi-D Intuitive, just like other languages. List inside a list [ [ 1, 2 ], [ 8, 6 ] ] Access element with multiple indices: list[3][2] Very often associated with nested loops Applications? –List of lines; list of words on the line –Board game

Examples Sudoku and Reversi

Exceptions Chapter 10 covers in great detail Similar to Java Find out what could go wrong with your code try-except block try : possibly exceptional code except Name_of_exception: what to do in case of problem

Exceptions Common types –ValueError –IOError –IndexError You can raise an exception if you discover something wrong: if value < 0: raise ValueError Another use of “raise”: raise SystemExit is a way out of your program.

Example while True: try: value = input("Enter a positive number") if value <= 0: raise ValueError else: break except ValueError: print "Please follow directions" continue print value