Slide Set 15 (Complete)

Size: px
Start display at page:

Download "Slide Set 15 (Complete)"

Transcription

1 Slide Set 15 (Complete) for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary November 2017

2 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 2/46 Contents About this complete version Dealing with failure How Python exceptions work try statement syntax A simple practical example of exception handling Introduction to text file input/output with Python A brief digression on class inheritance Exceptions and file operations Coming up in Slide Set 16

3 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 3/46 Outline of Slide Set 15 (Complete) About this complete version Dealing with failure How Python exceptions work try statement syntax A simple practical example of exception handling Introduction to text file input/output with Python A brief digression on class inheritance Exceptions and file operations Coming up in Slide Set 16

4 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 4/46 About this complete version Slides 5 31 are the same as in the incomplete version that was posted earlier. Slides are new.

5 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 5/46 Outline of Slide Set 15 (Complete) About this complete version Dealing with failure How Python exceptions work try statement syntax A simple practical example of exception handling Introduction to text file input/output with Python A brief digression on class inheritance Exceptions and file operations Coming up in Slide Set 16

6 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 6/46 Dealing with failure Things can go wrong when programs run. For example: Users can enter letters when a program needs digits. Attempts to open files can fail. Operations with a file can fail after the file has successfully been opened. C programmers are expected to check return values of functions for error situations, as outlined in the sketch of C code on the next slide...

7 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 7/46 result = do_something( /* arguments */ ); if (result == BAD) { /* deal with the error somehow */ } else { } /* do the normal work of the program */ do_something is a generic representative of functions such as scanf, fopen, fread, fclose, malloc, and many, many others.

8 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 8/46 There are at least two serious and valid criticisms of the C approach to failure checking: The code to manage failures makes programs hard for humans to read the normal program flow when failure doesn t happen can be hard to pick out. This is especially the case when multiple failures are possible, leading to if-statements within if-statements within if-statements. Programmers sometimes just don t write code needed to check for failure, because they believe (correctly or incorrectly) that some kinds of failure are very unlikely to happen.

9 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 9/46 Exception handling Exception handling is an approach to failure management that is quite different from checking function return values for error indications. Python and Java are prominent examples of languages that use exception handling to manage failure events. (C++, an extremely powerful, flexible, and messy language, makes its programmers worry about both error-indicating return values and exception handling.)

10 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 10/46 Advantages of exception handling Here are two: Compared to looking for error-indicating return values, exception handling allows significantly better separation of deal with the unusual error code from deal with the normal no-error case code. If exceptions are not handled, mechanisms such as the Python traceback system can help developers understand the exact cause of a program failure.

11 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 11/46 Outline of Slide Set 15 (Complete) About this complete version Dealing with failure How Python exceptions work try statement syntax A simple practical example of exception handling Introduction to text file input/output with Python A brief digression on class inheritance Exceptions and file operations Coming up in Slide Set 16

12 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 12/46 How Python exceptions work The next few slides are intended to illustrate the basic mechanisms of Python and are not provided as models for good software design! The program on the slide 13 has code that tries to add 120 to an int values encoded in a string, in a rather awkward way. Slide 14 shows what happens when it runs. Let s make some detailed notes about the sequence of events that lead to program termination with traceback.

13 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 13/46 1 def add_20(s): 2 print( add_20 arrival ) 3 q = int(s) print( add_20 departure ) 5 return q 6 7 def add_120(t): 8 print( add_120 arrival ) 9 r = add_20(t) print( add_120 departure ) 11 return r print( 1st result:, add_120( 4 )) 14 print( 2nd result, add_120( xyz ))

14 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 14/46 add_120 arrival add_20 arrival add_20 departure add_120 departure 1st result: 124 add_120 arrival add_20 arrival Traceback (most recent call last): File "program1.py", line 14, in <module> print( 2nd result, add_120( xyz )) File "program1.py", line 9, in add_120 r = add_20(t) File "program1.py", line 3, in add_20 q = int(s) + 20 ValueError: invalid literal for int() with base 10: xyz

15 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 15/46 The try statement The program on slide 16 is similar to the previous Python program, but the new program puts its calls to add_120 inside a thing called a try statemennt. The output of the new program is on slide 17.

16 1 def add_20(s): 2 print( add_20 arrival ) 3 q = int(s) print( add_20 departure ) 5 return q 6 7 def add_120(t): 8 print( add_120 arrival ) 9 r = add_20(t) print( add_120 departure ) 11 return r try: 14 print( 1st result:, add_120( 4 )) 15 print( 2nd result, add_120( xyz )) 16 except ValueError as value_error: 17 print( something went wrong... ) 18 print(value_error)

17 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 17/46 add_120 arrival add_20 arrival add_20 departure add_120 departure 1st result: 124 add_120 arrival add_20 arrival something went wrong... invalid literal for int() with base 10: xyz Let s make some notes about how the new program differs in behaviour from the older program.

18 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 18/46 Outline of Slide Set 15 (Complete) About this complete version Dealing with failure How Python exceptions work try statement syntax A simple practical example of exception handling Introduction to text file input/output with Python A brief digression on class inheritance Exceptions and file operations Coming up in Slide Set 16

19 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 19/46 try statement syntax and rules for execution There are several different variations of try statement syntax. Let s just look at two simple ones instead of trying to cover all of the possibilities. Let s make some notes about the following syntax, which is the syntax used in the most recent example program. try: statements for usual program activity except exception class type as object name : statements to deal with the exception

20 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 20/46 If you are not interested in having an object to print or otherwise get information from, you may use this slightly simpler syntax... try: statements for usual program activity except exception class type : statements to deal with the exception In either kind of try statement, the part of the statement that begins with except is called an except clause.

21 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 21/46 Rules for execution of except clauses Will an except clause handle an exception of a specific type, or will the clause choose not to handle the exception? The essential rules are most easily presented by example. What will happen when this tiny program runs, and why? try: x = int( pqr ) except ValueError: print( There was a ValueError exception. )

22 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 22/46 Behaviour with this next program will be quite different. Why? try: y = 19 + two except ValueError: print( There was a ValueError exception. ) The complete rules for matching the type of an exception against the type named in an except clause involve class inheritance in a major way. We ll look at the details of that later, if time permits.

23 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 23/46 Outline of Slide Set 15 (Complete) About this complete version Dealing with failure How Python exceptions work try statement syntax A simple practical example of exception handling Introduction to text file input/output with Python A brief digression on class inheritance Exceptions and file operations Coming up in Slide Set 16

24 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 24/46 A simple practical example of exception handling A program that will add three integers typed in by a user is very much the opposite of an exciting application! But it shows how two programming goals can be accomplished... Users who are not Python programmers would like understandable error messages, not tracebacks. As much as possible, error-handling code should be separated from normal case code. Let s make some notes about the program on the next slide, then write out some example dialogs with the program.

25 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 25/46 try: a = int(input( enter 1st int: )) b = int(input( enter 2rd int: )) c = int(input( enter 3rd int: )) f = {} + {} + {} = {}. print(f.format(a, b, c, a + b + c)) except ValueError: print( Problem trying get an int from input. )

26 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 26/46 Outline of Slide Set 15 (Complete) About this complete version Dealing with failure How Python exceptions work try statement syntax A simple practical example of exception handling Introduction to text file input/output with Python A brief digression on class inheritance Exceptions and file operations Coming up in Slide Set 16

27 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 27/46 Introduction to text file input/output with Python Let s look at text file input in Python first, then look at text file output later. Before we get to Python details, let s review some material from a slide set much earlier in the term...

28 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 28/46 The basic set of steps to read input from a file is common to most programming languages and libraries, and is not specific to C: 1. Obtain a file name. (In C, that means get a character string.) 2. Open the file for input make a connection between the program and the file. The connection will allow the program to read character codes from the file. 3. Read some characters from the file. 4. Close the file break the connection between the program and the file.

29 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 29/46 Here s an overview of those steps in Python: 1. Obtain a file name. In Python, that means get a str object. 2. Open the file for input by calling the builtin open function. If this call succeeds, it will return a reference to a file object. (If the call fails, there will be an exception.) 3. Read some characters from the file, using method calls such as read, readline, and/or readlines on the file object. 4. Close the file by calling the close method on the file object.

30 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 30/46 An old text file input example Suppose that we have some text files that contain nothing but representations of numbers separated by whitespace. Here are a few examples of these files... f1.txt f2.txt e f3.txt By the way, what does 4.0e-2 mean?

31 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 31/46 Let s write a Python program that can read this kind of file, and tell the user how many numbers were in the file, what the sum of the numbers is, and what the average of the numbers is. The program should detect invalid input files, such as f4.txt Hello! 33 In contrast to the C solution to this problem, let s do Step 1 (obtain a file name), by getting a string from the command line used to start the Python interpreter.

32 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 32/46 The solution just given (in doc cam notes) to the problem described on slides 30 and 31 read the entire contents of an input file into program memory with a single method call. What are the advantages of taking that approach? What is potentially bad about reading all of a file into program memory?

33 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 33/46 Reading lines one at a time from a text file The readline method (which does not have s in its name) attempts to read a single line from an input file. What will be the program output, and why? def process_line(line): print(len(line)) f_object = open( foo.txt, r ) while True: line = f_object.readline() if len(line) == 0: break process_line(line) f_object.close() foo.txt contents: this is the file called foo.txt

34 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 34/46 The code on the previous slide works, but Python offers a much nicer way to do the job a text file open for reading can be processed as a sequence of lines... def process_line(line): print(len(line)) f_object = open( foo.txt, r ) for line in f_object: process_line(line) f_object.close() foo.txt contents: this is the file called foo.txt The output of the above program will be exactly the same as the output of the slide 33 program.

35 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 35/46 Outline of Slide Set 15 (Complete) About this complete version Dealing with failure How Python exceptions work try statement syntax A simple practical example of exception handling Introduction to text file input/output with Python A brief digression on class inheritance Exceptions and file operations Coming up in Slide Set 16

36 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 36/46 A brief digression on class inheritance We ll soon see that this digression is quite relevant to the problem of designing exception-handling for text file operations. Recall the dog classes from Slide Set 14: SmartDog was the original base class; PlusDog and TimesDog each inherited directly from SmartDog; SmartestDog inherited directly from both PlusDog and TimesDog.

37 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 37/46 Those sorts of relationships are often shown in inheritance diagrams, in which one or more arrows point from a class to the class(es) that it inherits from directly... SmartDog PlusDog TimesDog SmartestDog It s important to note that SmartestDog inherits indirectly from SmartDog. A SmartestDog object is a kind of SmartDog object.

38 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 38/46 An object X is said to be an instance of class C if either of the following is true: the actual class of X is C; the class of X inherits directly or indirectly from C. In Python, it s easy to write code to ask if X is an instance of C using the builtin isinstance function. Assuming class definitions as given in Slide Set 14, what is the output of the program on the next slide?

39 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 39/46 def instance_check(dog): print( SmartDog?, isinstance(dog, SmartDog)) print( PlusDog?, isinstance(dog, PlusDog)) print( TimesDog?, isinstance(dog, TimesDog)) print( SmartestDog?, isinstance(dog, SmartestDog)) alice = SmartestDog( arf!, 3) print( facts about alice... ) instance_check(alice) bob = TimesDog( ruff!, 2) print( facts about bob... ) instance_check(bob) alice.say_age()

40 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 40/46 Inheritance and exception handling We re now in a position to tersely and precisely answer the question, When will the except clause handle an exception that may come from scary_function, and when will it not? def scary_function(a): result = 0 #... do things that might fail... return result try: x = scary_function(7) print(x) except FooError: print( A FooError has been handled. ) What s the answer?

41 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 41/46 Outline of Slide Set 15 (Complete) About this complete version Dealing with failure How Python exceptions work try statement syntax A simple practical example of exception handling Introduction to text file input/output with Python A brief digression on class inheritance Exceptions and file operations Coming up in Slide Set 16

42 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 42/46 Exceptions and file operations The general form of a call to open is variable = open( filename, mode ) where both arguments have type str. Here are some of the available modes: mode meaning r open text file for input w open text file for output, either creating a new file or replacing an existing one a open text file for output, either creating a new file or adding text at the end of an existing one x open text file for output, but only if the file does not already exist

43 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 43/46 Given the information on the previous slide, let s make an incomplete list of the ways open could fail and raise an exception. Then let s make some notes relating that list to this (very incomplete) inheritance diagram for Python Standard Library exception types... Exception OSError FileNotFoundError PermissionError FileExistsError

44 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 44/46 Let s sketch a general outline of Python code that can gracefully recover from a failure of a call to open. What is a flaw in this approach? Slide Set 16 will show how use of a with statement can avoid such flawed program behaviour.

45 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 45/46 Outline of Slide Set 15 (Complete) About this complete version Dealing with failure How Python exceptions work try statement syntax A simple practical example of exception handling Introduction to text file input/output with Python A brief digression on class inheritance Exceptions and file operations Coming up in Slide Set 16

46 ENCM 339 Fall 2017 Section 01 Slide Set 15 (Complete) slide 46/46 Coming up in Slide Set 16 For sure... Python text file output example(s) with statements and file operations Maybe... Python modules introduction to recursive problem-solving

Slide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng

Slide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng Slide Set 2 for ENCM 335 in Fall 2018 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2018 ENCM 335 Fall 2018 Slide Set 2 slide

More information

Slide Set 3. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Slide Set 3. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng Slide Set 3 for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2017 ENCM 339 Fall 2017 Section 01

More information

Slide Set 8. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Slide Set 8. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng Slide Set 8 for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary October 2017 ENCM 339 Fall 2017 Section 01 Slide

More information

Slide Set 3. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 3. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 3 for ENCM 339 Fall 2016 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2016 ENCM 339 Fall 2016 Slide Set 3 slide 2/46

More information

Exceptions CS GMU

Exceptions CS GMU Exceptions CS 112 @ GMU Exceptions When an unrecoverable action takes place, normal control flow is abandoned: an exception value crashes outwards until caught. various types of exception values can be

More information

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 1 for ENCM 339 Fall 2016 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2016 ENCM 339 Fall 2016 Slide Set 1 slide 2/43

More information

ENCM 335 Fall 2018 Tutorial for Week 13

ENCM 335 Fall 2018 Tutorial for Week 13 ENCM 335 Fall 2018 Tutorial for Week 13 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary 06 December, 2018 ENCM 335 Tutorial 06 Dec 2018 slide

More information

Slide Set 8. for ENCM 501 in Winter Steve Norman, PhD, PEng

Slide Set 8. for ENCM 501 in Winter Steve Norman, PhD, PEng Slide Set 8 for ENCM 501 in Winter 2018 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary March 2018 ENCM 501 Winter 2018 Slide Set 8 slide

More information

ENCM 339 Fall 2017 Lecture Section 01 Lab 9 for the Week of November 20

ENCM 339 Fall 2017 Lecture Section 01 Lab 9 for the Week of November 20 page 1 of 9 ENCM 339 Fall 2017 Lecture Section 01 Lab 9 for the Week of November 20 Steve Norman Department of Electrical & Computer Engineering University of Calgary November 2017 Lab instructions and

More information

Slide Set 18. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Slide Set 18. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng Slide Set 18 for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary December 2017 ENCM 339 Fall 2017 Section 01

More information

Slide Set 5. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 5. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 5 for ENCM 339 Fall 2016 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary October 2016 ENCM 339 Fall 2016 Slide Set 5 slide 2/32

More information

ENCM 339 Fall 2017 Tutorial for Week 8

ENCM 339 Fall 2017 Tutorial for Week 8 ENCM 339 Fall 2017 Tutorial for Week 8 for section T01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary 2 November, 2017 ENCM 339 T01 Tutorial

More information

ENCM 335 Fall 2018 Lab 6 for the Week of October 22 Complete Instructions

ENCM 335 Fall 2018 Lab 6 for the Week of October 22 Complete Instructions page 1 of 5 ENCM 335 Fall 2018 Lab 6 for the Week of October 22 Complete Instructions Steve Norman Department of Electrical & Computer Engineering University of Calgary October 2018 Lab instructions and

More information

Slide Set 9. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 9. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 9 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary March 2018 ENCM 369 Winter 2018 Section 01

More information

ENCM 339 Fall 2017: Editing and Running Programs in the Lab

ENCM 339 Fall 2017: Editing and Running Programs in the Lab page 1 of 8 ENCM 339 Fall 2017: Editing and Running Programs in the Lab Steve Norman Department of Electrical & Computer Engineering University of Calgary September 2017 Introduction This document is a

More information

Slide Set 14. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 14. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 14 for ENCM 339 Fall 2016 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary November 2016 ENCM 339 Fall 2016 Slide Set 14 slide 2/35

More information

Slide Set 18. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 18. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 18 for ENCM 339 Fall 2016 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary December 2016 ENCM 339 Fall 2016 Slide Set 18 slide 2/26

More information

Slides for Lecture 6

Slides for Lecture 6 Slides for Lecture 6 ENCM 501: Principles of Computer Architecture Winter 2014 Term Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary 28 January,

More information

Slide Set 4. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 4. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 4 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary January 2018 ENCM 369 Winter 2018 Section

More information

University of Calgary Department of Electrical and Computer Engineering ENCM 339: Programming Fundamentals, Section 01 Instructor: Steve Norman

University of Calgary Department of Electrical and Computer Engineering ENCM 339: Programming Fundamentals, Section 01 Instructor: Steve Norman page 1 of 9 University of Calgary Department of Electrical and Computer Engineering ENCM 339: Programming Fundamentals, Section 01 Instructor: Steve Norman Fall 2017 FINAL EXAMINATION Location: ENG 60

More information

Integer Multiplication and Division

Integer Multiplication and Division Integer Multiplication and Division for ENCM 369: Computer Organization Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 208 Integer

More information

ENCM 501 Winter 2016 Assignment 1 for the Week of January 25

ENCM 501 Winter 2016 Assignment 1 for the Week of January 25 page 1 of 5 ENCM 501 Winter 2016 Assignment 1 for the Week of January 25 Steve Norman Department of Electrical & Computer Engineering University of Calgary January 2016 Assignment instructions and other

More information

MEIN 50010: Python Flow Control

MEIN 50010: Python Flow Control : Python Fabian Sievers Higgins Lab, Conway Institute University College Dublin Wednesday, 2017-10-11 Program Overview Program Code Block Statements Expressions Expressions & Statements An expression has

More information

Contents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides

Contents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides Slide Set 1 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014 ENCM 369 W14 Section

More information

Contents. Slide Set 2. Outline of Slide Set 2. More about Pseudoinstructions. Avoid using pseudoinstructions in ENCM 369 labs

Contents. Slide Set 2. Outline of Slide Set 2. More about Pseudoinstructions. Avoid using pseudoinstructions in ENCM 369 labs Slide Set 2 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014 ENCM 369 W14 Section

More information

EXAMINATION REGULATIONS and REFERENCE MATERIAL for ENCM 339 Fall 2017 Section 01 Final Examination

EXAMINATION REGULATIONS and REFERENCE MATERIAL for ENCM 339 Fall 2017 Section 01 Final Examination EXAMINATION REGULATIONS and REFERENCE MATERIAL for ENCM 339 Fall 2017 Section 01 Final Examination The following regulations are taken from the front cover of a University of Calgary examination answer

More information

Slide Set 14. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 14. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 14 for ENCM 339 Fall 2015 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Fall Term, 2015 SN s ENCM 339 Fall 2015 Slide Set 14 slide

More information

Fundamentals of Programming Session 4

Fundamentals of Programming Session 4 Fundamentals of Programming Session 4 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2011 These slides are created using Deitel s slides, ( 1992-2010 by Pearson Education, Inc).

More information

Slide Set 4. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Slide Set 4. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng Slide Set 4 for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2017 ENCM 339 Fall 2017 Section 01

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

Slide Set 4. for ENCM 335 in Fall Steve Norman, PhD, PEng

Slide Set 4. for ENCM 335 in Fall Steve Norman, PhD, PEng Slide Set 4 for ENCM 335 in Fall 2018 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2018 ENCM 335 Fall 2018 Slide Set 4 slide

More information

Slides for Lecture 15

Slides for Lecture 15 Slides for Lecture 5 ENEL 353: Digital Circuits Fall 203 Term Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary October, 203 ENEL 353 F3 Section

More information

Functions and Decomposition

Functions and Decomposition Unit 4 Functions and Decomposition Learning Outcomes Design and implement functions to carry out a particular task. Begin to evaluate when it is necessary to split some work into functions. Locate the

More information

Slide Set 9. for ENCM 335 in Fall Steve Norman, PhD, PEng

Slide Set 9. for ENCM 335 in Fall Steve Norman, PhD, PEng Slide Set 9 for ENCM 335 in Fall 2018 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary October 2018 ENCM 335 Fall 2018 Slide Set 9 slide 2/32

More information

Slide Set 5. for ENCM 501 in Winter Term, Steve Norman, PhD, PEng

Slide Set 5. for ENCM 501 in Winter Term, Steve Norman, PhD, PEng Slide Set 5 for ENCM 501 in Winter Term, 2017 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2017 ENCM 501 W17 Lectures: Slide

More information

Slide Set 5. for ENEL 353 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 5. for ENEL 353 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 5 for ENEL 353 Fall 207 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Fall Term, 207 SN s ENEL 353 Fall 207 Slide Set 5 slide

More information

Slide Set 6. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Slide Set 6. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng Slide Set 6 for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary October 2017 ENCM 339 Fall 2017 Section 01 Slide

More information

ENCM 501 Winter 2018 Assignment 2 for the Week of January 22 (with corrections)

ENCM 501 Winter 2018 Assignment 2 for the Week of January 22 (with corrections) page 1 of 5 ENCM 501 Winter 2018 Assignment 2 for the Week of January 22 (with corrections) Steve Norman Department of Electrical & Computer Engineering University of Calgary January 2018 Assignment instructions

More information

Slide Set 11. for ENCM 369 Winter 2015 Lecture Section 01. Steve Norman, PhD, PEng

Slide Set 11. for ENCM 369 Winter 2015 Lecture Section 01. Steve Norman, PhD, PEng Slide Set 11 for ENCM 369 Winter 2015 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2015 ENCM 369 W15 Section

More information

Python Intro GIS Week 1. Jake K. Carr

Python Intro GIS Week 1. Jake K. Carr GIS 5222 Week 1 Why Python It s simple and easy to learn It s free - open source! It s cross platform IT S expandable!! Why Python: Example Consider having to convert 1,000 shapefiles into feature classes

More information

CS 115 Data Types and Arithmetic; Testing. Taken from notes by Dr. Neil Moore

CS 115 Data Types and Arithmetic; Testing. Taken from notes by Dr. Neil Moore CS 115 Data Types and Arithmetic; Testing Taken from notes by Dr. Neil Moore Statements A statement is the smallest unit of code that can be executed on its own. So far we ve seen simple statements: Assignment:

More information

Slide Set 5. for ENCM 369 Winter 2014 Lecture Section 01. Steve Norman, PhD, PEng

Slide Set 5. for ENCM 369 Winter 2014 Lecture Section 01. Steve Norman, PhD, PEng Slide Set 5 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014 ENCM 369 W14 Section

More information

Contents Slide Set 9. Final Notes on Textbook Chapter 7. Outline of Slide Set 9. More about skipped sections in Chapter 7. Outline of Slide Set 9

Contents Slide Set 9. Final Notes on Textbook Chapter 7. Outline of Slide Set 9. More about skipped sections in Chapter 7. Outline of Slide Set 9 slide 2/41 Contents Slide Set 9 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014

More information

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

CMSC 201 Fall 2016 Lab 09 Advanced Debugging CMSC 201 Fall 2016 Lab 09 Advanced Debugging Assignment: Lab 09 Advanced Debugging Due Date: During discussion Value: 10 points Part 1: Introduction to Errors Throughout this semester, we have been working

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Iterators, Generators, Exceptions & IO Raymond Yin University of Pennsylvania September 28, 2016 Raymond Yin (University of Pennsylvania) CIS 192 September 28, 2016 1 / 26 Outline

More information

CSE : Python Programming. Homework 5 and Projects. Announcements. Course project: Overview. Course Project: Grading criteria

CSE : Python Programming. Homework 5 and Projects. Announcements. Course project: Overview. Course Project: Grading criteria CSE 399-004: Python Programming Lecture 5: Course project and Exceptions February 12, 2007 Announcements Still working on grading Homeworks 3 and 4 (and 2 ) Homework 5 will be out by tomorrow morning I

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Object Oriented Programming Harry Smith University of Pennsylvania February 15, 2016 Harry Smith (University of Pennsylvania) CIS 192 Lecture 5 February 15, 2016 1 / 26 Outline

More information

12. Logical Maneuvers. Topics: Loop-Body Returns Exceptions Assertions Type Checking Try-Except

12. Logical Maneuvers. Topics: Loop-Body Returns Exceptions Assertions Type Checking Try-Except 12. Logical Maneuvers Topics: Loop-Body Returns Exceptions Assertions Type Checking Try-Except Loop-Body Returns Loop-Body Returns Another way to terminate a loop. Uses the fact that in a function, control

More information

Chapter 9: Dealing with Errors

Chapter 9: Dealing with Errors Chapter 9: Dealing with Errors What we will learn: How to identify errors Categorising different types of error How to fix different errors Example of errors What you need to know before: Writing simple

More information

Slide Set 8. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 8. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 8 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary March 2018 ENCM 369 Winter 2018 Section 01

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

Slide Set 1 (corrected)

Slide Set 1 (corrected) Slide Set 1 (corrected) for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary January 2018 ENCM 369 Winter 2018

More information

Introduction to python

Introduction to python Introduction to python 13 Files Rossano Venturini rossano.venturini@unipi.it File System A computer s file system consists of a tree-like structured organization of directories and files directory file

More information

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng Slide Set 1 for ENEL 339 Fall 2014 Lecture Section 02 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Fall Term, 2014 ENEL 353 F14 Section

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Iterators, Generators, IO, and Exceptions Harry Smith University of Pennsylvania February 15, 2018 Harry Smith (University of Pennsylvania) CIS 192 Lecture 5 February 15, 2018

More information

Loop structures and booleans

Loop structures and booleans Loop structures and booleans Michael Mandel Lecture 7 Methods in Computational Linguistics I The City University of New York, Graduate Center https://github.com/ling78100/lectureexamples/blob/master/lecture07final.ipynb

More information

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS 164 Spring 2005 P. N. Hilfinger Project #2: Static Analyzer for Pyth Due: Wednesday, 6 April

More information

Unit E Step-by-Step: Programming with Python

Unit E Step-by-Step: Programming with Python Unit E Step-by-Step: Programming with Python Computer Concepts 2016 ENHANCED EDITION 1 Unit Contents Section A: Hello World! Python Style Section B: The Wacky Word Game Section C: Build Your Own Calculator

More information

Lecture 9: July 14, How to Think About Debugging

Lecture 9: July 14, How to Think About Debugging Lecture 9: July 14, 2011 How to Think About Debugging So, you wrote your program. And, guess what? It doesn t work. L Your program has a bug in it Somehow, you must track down the bug and fix it Need to

More information

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners Getting Started Excerpted from Hello World! Computer Programming for Kids and Other Beginners EARLY ACCESS EDITION Warren D. Sande and Carter Sande MEAP Release: May 2008 Softbound print: November 2008

More information

A Problem. Loop-Body Returns. While-Loop Solution with a Loop-Body Return. 12. Logical Maneuvers. Typical While-Loop Solution 3/8/2016

A Problem. Loop-Body Returns. While-Loop Solution with a Loop-Body Return. 12. Logical Maneuvers. Typical While-Loop Solution 3/8/2016 12. Logical Maneuvers Topics: Loop-Body Returns Exceptions Assertions Type Checking Try-Except Loop-Body Returns Loop-Body Returns Another way to terminate a loop. Uses the fact that in a function, control

More information

Text Input and Conditionals

Text Input and Conditionals Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()

More information

Errors. Lecture 6. Hartmut Kaiser hkaiser/fall_2011/csc1254.html

Errors. Lecture 6. Hartmut Kaiser  hkaiser/fall_2011/csc1254.html Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/ hkaiser/fall_2011/csc1254.html 2 Abstract When we program, we have to deal with errors. Our most basic aim is correctness, but we must deal with

More information

The Dynamic Typing Interlude

The Dynamic Typing Interlude CHAPTER 6 The Dynamic Typing Interlude In the prior chapter, we began exploring Python s core object types in depth with a look at Python numbers. We ll resume our object type tour in the next chapter,

More information

Python Essential Reference, Second Edition - Chapter 5: Control Flow Page 1 of 8

Python Essential Reference, Second Edition - Chapter 5: Control Flow Page 1 of 8 Python Essential Reference, Second Edition - Chapter 5: Control Flow Page 1 of 8 Chapter 5: Control Flow This chapter describes related to the control flow of a program. Topics include conditionals, loops,

More information

CS 115 Lecture 4. More Python; testing software. Neil Moore

CS 115 Lecture 4. More Python; testing software. Neil Moore CS 115 Lecture 4 More Python; testing software Neil Moore Department of Computer Science University of Kentucky Lexington, Kentucky 40506 neil@cs.uky.edu 8 September 2015 Syntax: Statements A statement

More information

Chapter 5 Errors. Hyunyoung Lee. Based on slides by Bjarne Stroustrup.

Chapter 5 Errors. Hyunyoung Lee. Based on slides by Bjarne Stroustrup. Chapter 5 Errors Hyunyoung Lee Based on slides by Bjarne Stroustrup www.stroustrup.com/programming 1 Abstract When we program, we have to deal with errors. Our most basic aim is correctness, but we must

More information

ENCM 335 Fall 2018 Lab 2 for the Week of September 24

ENCM 335 Fall 2018 Lab 2 for the Week of September 24 page 1 of 8 ENCM 335 Fall 2018 Lab 2 for the Week of September 24 Steve Norman Department of Electrical & Computer Engineering University of Calgary September 2018 Lab instructions and other documents

More information

Errors. And How to Handle Them

Errors. And How to Handle Them Errors And How to Handle Them 1 GIGO There is a saying in computer science: Garbage in, garbage out. Is this true, or is it just an excuse for bad programming? Answer: Both. Here s what you want: Can you

More information

A Little Python Part 3

A Little Python Part 3 A Little Python Part 3 Introducing Programming with Python I/O, Files, Object Classes, Exception Handling Outline I/O Files opening File I/O, reading writing Python Objects Defining a new object Inheritance

More information

Lecture 5 8/24/18. Writing larger programs. Comments. What are we going to cover today? Using Comments. Comments in Python. Writing larger programs

Lecture 5 8/24/18. Writing larger programs. Comments. What are we going to cover today? Using Comments. Comments in Python. Writing larger programs What are we going to cover today? Lecture 5 Writing and Testing Programs Writing larger programs Commenting Design Testing Writing larger programs As programs become larger and more complex, it becomes

More information

Programming and Data Structure

Programming and Data Structure Programming and Data Structure Dr. P.P.Chakraborty Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture # 09 Problem Decomposition by Recursion - II We will

More information

APT Session 2: Python

APT Session 2: Python APT Session 2: Python Laurence Tratt Software Development Team 2017-10-20 1 / 17 http://soft-dev.org/ What to expect from this session: Python 1 What is Python? 2 Basic Python functionality. 2 / 17 http://soft-dev.org/

More information

COMP 102: Computers and Computing

COMP 102: Computers and Computing COMP 102: Computers and Computing Lecture 5: What is Programming? Instructor: Kaleem Siddiqi (siddiqi@cim.mcgill.ca) Class web page: www.cim.mcgill.ca/~siddiqi/102.html Motivation The advantage of a computer

More information

Slides for Lecture 15

Slides for Lecture 15 Slides for Lecture 15 ENCM 501: Principles of Computer Architecture Winter 2014 Term Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary 6 March,

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #47. File Handling

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #47. File Handling Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #47 File Handling In this video, we will look at a few basic things about file handling in C. This is a vast

More information

Writing to and reading from files

Writing to and reading from files Writing to and reading from files printf() and scanf() are actually short-hand versions of more comprehensive functions, fprintf() and fscanf(). The difference is that fprintf() includes a file pointer

More information

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

More information

Introduction to Python and Programming. 1. Python is Like a Calculator. You Type Expressions. Python Computes Their Values /2 2**3 3*4+5*6

Introduction to Python and Programming. 1. Python is Like a Calculator. You Type Expressions. Python Computes Their Values /2 2**3 3*4+5*6 1. Python is a calculator. A variable is a container Introduction to Python and Programming BBM 101 - Introduction to Programming I Hacettepe University Fall 016 Fuat Akal, Aykut Erdem, Erkut Erdem 3.

More information

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications Hello World! Computer Programming for Kids and Other Beginners by Warren Sande and Carter Sande Chapter 1 Copyright 2009 Manning Publications brief contents Preface xiii Acknowledgments xix About this

More information

CS 103 Lab The Files are *In* the Computer

CS 103 Lab The Files are *In* the Computer CS 103 Lab The Files are *In* the Computer 1 Introduction In this lab you will modify a word scramble game so that instead of using a hardcoded word list, it selects a word from a file. You will learn

More information

Type Checking and Type Equality

Type Checking and Type Equality Type Checking and Type Equality Type systems are the biggest point of variation across programming languages. Even languages that look similar are often greatly different when it comes to their type systems.

More information

PREPARING FOR PRELIM 1

PREPARING FOR PRELIM 1 PREPARING FOR PRELIM 1 CS 1110: FALL 2012 This handout explains what you have to know for the first prelim. There will be a review session with detailed examples to help you study. To prepare for the prelim,

More information

A Little Python Part 3

A Little Python Part 3 A Little Python Part 3 Introducing Programming with Python I/O, Files, Object Classes, Exception Handling Outline I/O Files opening File I/O, reading writing Python Objects Defining a new object Inheritance

More information

Class extension and. Exception handling. Genome 559

Class extension and. Exception handling. Genome 559 Class extension and Exception handling Genome 559 Review - classes 1) Class constructors - class MyClass: def init (self, arg1, arg2): self.var1 = arg1 self.var2 = arg2 foo = MyClass('student', 'teacher')

More information

cs1114 REVIEW of details test closed laptop period

cs1114 REVIEW of details test closed laptop period python details DOES NOT COVER FUNCTIONS!!! This is a sample of some of the things that you are responsible for do not believe that if you know only the things on this test that they will get an A on any

More information

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA 1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared

More information

ENCM 501 Winter 2015 Tutorial for Week 5

ENCM 501 Winter 2015 Tutorial for Week 5 ENCM 501 Winter 2015 Tutorial for Week 5 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary 11 February, 2015 ENCM 501 Tutorial 11 Feb 2015 slide

More information

Introduction to Python

Introduction to Python Introduction to Python Reading assignment: Perkovic text, Ch. 1 and 2.1-2.5 Python Python is an interactive language. Java or C++: compile, run Also, a main function or method Python: type expressions

More information

Chapter 5 Errors. Bjarne Stroustrup

Chapter 5 Errors. Bjarne Stroustrup Chapter 5 Errors Bjarne Stroustrup www.stroustrup.com/programming Abstract When we program, we have to deal with errors. Our most basic aim is correctness, but we must deal with incomplete problem specifications,

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Generators Exceptions and IO Eric Kutschera University of Pennsylvania February 13, 2015 Eric Kutschera (University of Pennsylvania) CIS 192 February 13, 2015 1 / 24 Outline 1

More information

1 Classes. 2 Exceptions. 3 Using Other Code. 4 Problems. Sandeep Sadanandan (TU, Munich) Python For Fine Programmers May 16, / 19

1 Classes. 2 Exceptions. 3 Using Other Code. 4 Problems. Sandeep Sadanandan (TU, Munich) Python For Fine Programmers May 16, / 19 1 Classes 2 Exceptions 3 Using Other Code 4 Problems Sandeep Sadanandan (TU, Munich) Python For Fine Programmers May 16, 2009 1 / 19 Start with an Example Python is object oriented Everything is an object

More information

Slide Set 3. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 3. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 3 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary January 2018 ENCM 369 Winter 2018 Section

More information

ENCM 501 Winter 2019 Assignment 9

ENCM 501 Winter 2019 Assignment 9 page 1 of 6 ENCM 501 Winter 2019 Assignment 9 Steve Norman Department of Electrical & Computer Engineering University of Calgary April 2019 Assignment instructions and other documents for ENCM 501 can

More information

Week - 04 Lecture - 01 Merge Sort. (Refer Slide Time: 00:02)

Week - 04 Lecture - 01 Merge Sort. (Refer Slide Time: 00:02) Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 04 Lecture - 01 Merge Sort (Refer

More information

Extended Introduction to Computer Science CS1001.py. Lecture 5 Part A: Integer Representation (in Binary and other bases)

Extended Introduction to Computer Science CS1001.py. Lecture 5 Part A: Integer Representation (in Binary and other bases) Extended Introduction to Computer Science CS1001.py Lecture 5 Part A: Integer Representation (in Binary and other bases) Instructors: Daniel Deutch, Amir Rubinstein Teaching Assistants: Michal Kleinbort,

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Python Programming: An Introduction to Computer Science Chapter 7 Decision Structures Python Programming, 2/e 1 Objectives æ To understand the programming pattern simple decision and its implementation

More information

Lecture Transcript While and Do While Statements in C++

Lecture Transcript While and Do While Statements in C++ Lecture Transcript While and Do While Statements in C++ Hello and welcome back. In this lecture we are going to look at the while and do...while iteration statements in C++. Here is a quick recap of some

More information

Chapter 1 Introduction

Chapter 1 Introduction Chapter 1 Introduction Why I Am Writing This: Why I am I writing a set of tutorials on compilers and how to build them? Well, the idea goes back several years ago when Rapid-Q, one of the best free BASIC

More information

CSc 120. Introduction to Computer Programming II. 07: Excep*ons. Adapted from slides by Dr. Saumya Debray

CSc 120. Introduction to Computer Programming II. 07: Excep*ons. Adapted from slides by Dr. Saumya Debray CSc 120 Introduction to Computer Programming II Adapted from slides by Dr. Saumya Debray 07: Excep*ons EXERCISE Type in the following code: def foo(): n = int(input("enter a number:")) print("n = ", n)

More information