Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53) [GCC 4.0.1 (Apple Computer, Inc. build 5363)] Type "help", "copyright", "credits" or "license" for more information. >>> 4 + 5 * 3 # operators have precedence 19 >>> (4 + 5) * 3 # override with parentheses 27 >>> # What if you do something that doesn't work? >>> 4/0 Traceback (most recent call last): File "", line 1, in ZeroDivisionError: integer division or modulo by zero >>> # For now, the last line is the only useful one >>> #not all error messages are as useful: >>> 4 + Traceback (most recent call last): File "", line 1, in invalid syntax: , line 1, pos 5 >>> # Above essentially says that is invalid python code >>> # dir and help are really useful builtin functions >>> # dir(x) tells you what is defined inside x >>> # help(x) displays the documentation for x >>> dir(media) # this is everything inside media Traceback (most recent call last): File "", line 1, in NameError: name 'media' is not defined >>> #what happened? Hmmmm >>> # I never imported media into the shell! >>> import media >>> dir(media) ['AUDIO_ENCODINGS', 'Color', 'DEFAULT_BUFFERING', 'DEFAULT_CHANNELS', 'DEFAULT_ENCODING', 'DEFAULT_FONT', 'DEFAULT_SAMP_RATE', 'GRAPH_COLOR_THEMES', 'IMAGE_FORMATS', 'Image', 'ImageDraw', 'ImageFont', 'ImageTk', 'Note', 'PIC_INITIALIZED', 'Picture', 'SND_INITIALIZED', 'SOUND_FORMATS', 'Sound', '__builtins__', '__doc__', '__file__', '__name__', 'add_line', 'add_oval', 'add_oval_filled', 'add_polygon', 'add_polygon_filled', 'add_rect', 'add_rect_filled', 'add_text', 'aliceblue', 'antiquewhite', 'append_silence', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'choose_color', 'choose_file', 'choose_folder', 'choose_save_filename', 'close', 'close_inspect', 'color', 'concatenate', 'copy', 'coral', 'cornflowerblue', 'cornsilk', 'create_color', 'create_image', 'create_note', 'create_picture', 'create_pygame_sound', 'create_sine_wave', 'create_sound', 'crimson', 'crop_picture', 'cr op_sound', 'cyan', 'darkblue', 'darkcyan', 'darken', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'distance', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'fuchsia', 'gainsboro', 'get_blue', 'get_color', 'get_green', 'get_height', 'get_index', 'get_left', 'get_max_sample', 'get_min_sample', 'get_pixel', 'get_pixels', 'get_red', 'get_right', 'get_sample', 'get_samples', 'get_sampling_rate', 'get_short_path', 'get_spectrogram', 'get_spectrum', 'get_value', 'get_values', 'get_waveform', 'get_width', 'get_x', 'get_y', 'ghostwhite', 'gold', 'goldenrod', 'gray', 'green', 'greenyellow', 'honeydew', 'hotpink', 'indianred', 'indigo', 'init_picture', 'init_sound', 'insert', 'inspect', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lighten', 'lightgoldenrodyellow', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslategray', 'lightsteelblue', 'lightyellow', 'lime', 'limegreen', 'linen', 'load_image', 'load_picture', 'load_pygame_sound', 'load_sound', 'magenta', 'maroon', 'math', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'mw', 'navajowhite', 'navy', 'numpy', 'oldlace', 'olive', 'olivedrab', 'orange', 'orangered', 'orchid', 'os', 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'picture', 'pink', 'pixel', 'play', 'play_in_range', 'plum', 'powderblue', 'purple', 'pygame', 'pygame_to_sample_array', 'red', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sample', 'sample_array_to_pygame', 'sandybrown', 'save', 'save_as', 's eagreen', 'seashell', 'set_blue', 'set_color', 'set_green', 'set_left', 'set_red', 'set_right', 'set_value', 'set_values', 'show', 'show_external', 'sienna', 'silver', 'skyblue', 'slateblue', 'slategray', 'sndhdr', 'snow', 'springgreen', 'steelblue', 'stop', 'tan', 'teal', 'thistle', 'tomato', 'turquoise', 'update', 'violet', 'wave', 'wheat', 'white', 'whitesmoke', 'yellow', 'yellowgreen'] >>> help(abs) Help on built-in function abs in module __builtin__: abs(...) abs(number) -> number Return the absolute value of the argument. >>> help(media.set_green) Help on function set_green in module media: set_green(pix, g) Set the green value of Pixel pix to g. >>> ## Next topic - variables and assignments >>> # In lecture, we traced through some programs. You also did that on the lab. >>> # >>> # You can use builtin function "type" to see the type of a value >>> type(3) >>> type(3 ** 4) >>> 7 7 >>> type(7) >>> type(34.64) >>> #remember floating point numbers are numbers with decimal places >>> # why is the type of (3 **4) an int? well... >>> 3 ** 4 81 >>> #see, 81 is an int >>> 8e+2 # means 8.0 * 10 ** 2 800.0 >>> type(8e+2) # these are type flaat >>> # suppose we need to convert from floats to ints >>> # for example, when accessing pixels of pictures >>> # there is no pixel 4.5 x 3.4 for example >>> int(34.5) 34 >>> #the fuction "int" chops off the decimal part of the number >>> # >>> # Programming languages have different symbols for equality >>> # and assignment >>> # assignment means; evaluate the right hand side, and place >>> # the value in the variable on the lhs >>> # on the other hand, equality is concerned with whether things are equal >>> # Make sure you understand the following sequence >>> t = 3 # assignment >>> t 3 >>> t == 3 # equality comparison True >>> t 3 >>> t == 5 False >>> t 3 >>>