Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> values = (10, 20, 30, 40, 50) >>> values["0"] Traceback (most recent call last): File "", line 1, in values["0"] TypeError: tuple indices must be integers, not str >>> ================================ RESTART ================================ >>> Get the value at which position? 0 The value at that position is 10 >>> ================================ RESTART ================================ >>> Get the value at which position? 5 Traceback (most recent call last): File "C:/Users/mil28/Desktop/list_pos_eh.py", line 5, in value = values[pos] IndexError: tuple index out of range >>> ================================ RESTART ================================ >>> Get the value at which position? 0 The value at that position is 10 >>> ================================ RESTART ================================ >>> Get the value at which position? 4 The value at that position is 50 >>> ================================ RESTART ================================ >>> Get the value at which position? 2 The value at that position is 30 >>> ================================ RESTART ================================ >>> Get the value at which position? -5 Position must be between 0 and 4 inclusive. Get the value at which position? -10 Position must be between 0 and 4 inclusive. Get the value at which position? 9 Position must be between 0 and 4 inclusive. Get the value at which position? 15 Position must be between 0 and 4 inclusive. Get the value at which position? 3 The value at that position is 40 >>> ================================ RESTART ================================ >>> Get the value at which position? 13.8 Traceback (most recent call last): File "C:/Users/mil28/Desktop/list_pos_eh.py", line 2, in pos = int(input("Get the value at which position? ")) ValueError: invalid literal for int() with base 10: '13.8' >>> 10 % 2 0 >>> 10.0 % 2 0.0 >>> 13.8 % 2 1.8000000000000007 >>> 10 % 1 0 >>> 10.0 % 1 0.0 >>> 13.8 % 1 0.8000000000000007 >>> 1e1 10.0 >>> int('13.8') Traceback (most recent call last): File "", line 1, in int('13.8') ValueError: invalid literal for int() with base 10: '13.8' >>> 5/0 Traceback (most recent call last): File "", line 1, in 5/0 ZeroDivisionError: division by zero >>> values[10] Traceback (most recent call last): File "", line 1, in values[10] IndexError: tuple index out of range >>> values.index(22) Traceback (most recent call last): File "", line 1, in values.index(22) ValueError: tuple.index(x): x not in tuple >>> try: 5/0 print('Able to divide by zero!') except ZeroDivisionError: print('Cannot divide by zero!') print('Must divide by another value.') except ValueError: print('Value error!') Cannot divide by zero! Must divide by another value. >>> 5/0 Traceback (most recent call last): File "", line 1, in 5/0 ZeroDivisionError: division by zero >>> ================================ RESTART ================================ >>> Before division 1 Before division 2 Before division 3 Cannot divide by zero! Must divide by another value. after try-except block >>> int('13.8') Traceback (most recent call last): File "", line 1, in int('13.8') ValueError: invalid literal for int() with base 10: '13.8' >>> ================================ RESTART ================================ >>> Before division 1 Before division 2 Before division 3 enter value: cat Value error! after try-except block >>> ================================ RESTART ================================ >>> Before division 1 Before division 2 Before division 3 enter value: 0 Cannot divide by zero! Must divide by another value. after try-except block >>> ================================ RESTART ================================ >>> Before division 1 Before division 2 Before division 3 enter value: -1 Able to divide by zero! after try-except block >>> ================================ RESTART ================================ >>> Get the value at which position? cst Position must be an integer. >>> ================================ RESTART ================================ >>> Get the value at which position? 13.78 Position must be an integer. >>> ================================ RESTART ================================ >>> Get the value at which position? 1.0 Position must be an integer. >>> int("10.0") Traceback (most recent call last): File "", line 1, in int("10.0") ValueError: invalid literal for int() with base 10: '10.0' >>> int(float("10.0")) 10 >>> int(float("13.8")) 13 >>> float('13.8') % 1 0.8000000000000007 >>> float('10.0') % 1 0.0 >>> ================================ RESTART ================================ >>> Get the value at what position? 10 Invalid position in list. >>> ================================ RESTART ================================ >>> Get the value at what position? 10 Error with input. >>> ================================ RESTART ================================ >>> Get the value at what position? 10 Unknown error occurred. >>> ================================ RESTART ================================ >>> Get the value at what position? cat Unknown error occurred. >>> ================================ RESTART ================================ >>> Get the value at what position? cat Unable to convert "cat" into an integer. >>> ================================ RESTART ================================ >>> Get the value at what position? 10 Invalid position in list. >>> ================================ RESTART ================================ >>> Get the value at what position? 2 Unknown error occurred. >>> ================================ RESTART ================================ >>> Get the value at what position? cat Unknown error occurred. >>> ================================ RESTART ================================ >>> Get the value at what position? >>> ================================ RESTART ================================ >>> Get the value at what position? cat Unknown error occurred. >>> ================================ RESTART ================================ >>> Get the value at what position? 5 Invalid position in list. 5 >>> ================================ RESTART ================================ >>> Get the value at what position? cat Unable to convert "cat" into an integer. cat >>> ================================ RESTART ================================ >>> Get the value at what position? 5 Invalid position in list. 5 Traceback (most recent call last): File "C:/Users/mil28/Desktop/index_eh.py", line 15, in print(value, type(value)) NameError: name 'value' is not defined >>> a = b + 5 Traceback (most recent call last): File "", line 1, in a = b + 5 NameError: name 'b' is not defined >>> ================================ RESTART ================================ >>> Get the value at what position? cat Unable to convert "cat" into an integer. Traceback (most recent call last): File "C:/Users/mil28/Desktop/index_eh.py", line 14, in print(position, type(position)) NameError: name 'position' is not defined >>> ================================ RESTART ================================ >>> Get the value at what position? cat Unable to convert "cat" into an integer. 3 Traceback (most recent call last): File "C:/Users/mil28/Desktop/index_eh.py", line 16, in print(value, type(value)) NameError: name 'value' is not defined >>> cat = 5 >>> cat(4) Traceback (most recent call last): File "", line 1, in cat(4) TypeError: 'int' object is not callable >>> ================================ RESTART ================================ >>> a this will print because ValueError is raised. err = invalid literal for int() with base 10: '13.8' type = >>> ================================ RESTART ================================ >>> a this will print because ValueError is raised. err = invalid literal for int() with base 10: '13.8' type = >>> ================================ RESTART ================================ >>> a this will print because ValueError is raised. err = invalid literal for int() with base 10: '13.8' type = dir = ['__cause__', '__class__', '__context__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__suppress_context__', '__traceback__', 'args', 'with_traceback'] >>> open('asdf', 'r') Traceback (most recent call last): File "", line 1, in open('asdf', 'r') FileNotFoundError: [Errno 2] No such file or directory: 'asdf' >>> try: open('asdf', 'r') except FileNotFoundError as fnfe: print(dir(fnfe)) ['__cause__', '__class__', '__context__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__suppress_context__', '__traceback__', 'args', 'characters_written', 'errno', 'filename', 'filename2', 'strerror', 'winerror', 'with_traceback'] >>> try: open('asdf', 'r') except FileNotFoundError as fnfe: print('bad filename:', fnfe.filename) bad filename: asdf >>> fnfe Traceback (most recent call last): File "", line 1, in fnfe NameError: name 'fnfe' is not defined >>> fnfe.filename Traceback (most recent call last): File "", line 1, in fnfe.filename NameError: name 'fnfe' is not defined >>> try: open('asdf', 'r') except FileNotFoundError as fnfe: print('bad filename:', fnfe.filename) a = fnfe bad filename: asdf >>> a FileNotFoundError(2, 'No such file or directory') >>>