Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Python – May 17 Recap lab Multidimensional list Exceptions Commitment: quiz tomorrow."— Presentation transcript:

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

2 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

3 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

4 Examples Sudoku and Reversi 175294836 6231745 89563271 51973246 3485129 86941753 9342567 41379582 7521839

5 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

6 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.

7 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


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

Similar presentations


Ads by Google