Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 16 2013, 23:39:35) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>> # running the function convert_base() >>> help(convert_base) Help on function convert_base in module __main__: convert_base(n, b) convert_base(int,int) -> str returns the str representation of n (decimal) in base 2<=b<=36 >>> convert_base(10,2) '1010' # the initial version of the function could not handle the following case >>> convert_base(10,16) '10' >>> ================================ RESTART ================================ # the improved version restricts the range of b >>> convert_base_imp(10,100) Traceback (most recent call last): File "", line 1, in convert_base_imp(10,100) File "/Users/Yael/Dropbox/cs1001/week3/4class/0a_convert_base.py", line 7, in convert_base_imp assert 2<=b<=36 AssertionError >>> convert_base_imp(10,16) 'a' # python has a built-in function for converting decimal to binary >>> bin(12) '0b1100' >>> bin(12)[2:] '1100' # python has a built-in function for converting a string which represents a number in a specified base to decimal >>> int("1100",2) 12 >>> int("1100",10) 1100 # motivating examples for studying python's memory model # a >>> def change_int(num): num=999 >>> n = 1 >>> n 1 >>> change_int(n) >>> n 1 # b >>> def add_to_list(lst): lst.append(999) >>> l = [1,2,3] >>> add_to_list(l) >>> l [1, 2, 3, 999] # c >>> def change_list(lst): lst = [999,999,999] >>> l = [1,2,3] >>> change_list(l) >>> l [1, 2, 3]