Python 3.1.2 (r312:79360M, Mar 24 2010, 01:33:18) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "copyright", "credits" or "license()" for more information. >>> def endless_timer (): import time now = 0 while (True): time.sleep(1) now = now + 1 print(now) >>> endless_time() Traceback (most recent call last): File "", line 1, in endless_time() NameError: name 'endless_time' is not defined >>> endless_timer() 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 Traceback (most recent call last): File "", line 1, in endless_timer() File "", line 5, in endless_timer time.sleep(1) KeyboardInterrupt >>> def endless_timer2 (): import time now = 0 while (True): time.sleep(1) print(now) now = now+1 >>> def seconds_stop_watch (total_seconds): import time now = 0 while (now < total_seconds): time.sleep(1) now = now + 1 print(now) >>> seconds_stop_watch(5) 1 2 3 4 5 >>> def seconds_stop_watch2 (total_seconds): import time for now in range(total_seconds): time.sleep(1) print(now) >>> seconds_stop_watch2(5) 0 1 2 3 4 >>> def seconds_stop_watch2 (total_seconds): import time for now in range(1,total_seconds+1): time.sleep(1) print(now) >>> seconds_stop_watch2(5) 1 2 3 4 5 >>> for character in 'This is a string.': print(character) T h i s i s a s t r i n g . >>> for item in [1,2,3,'apple',[1,2,3]]: print(item) 1 2 3 apple [1, 2, 3] >>> for iteration in range(5): print('hello') hello hello hello hello hello >>> def for_string_loop (string): for letter in string: print(letter) >>> def while_string_loop (string): position = 0 while(position < len(string)) print(string[position]) position = 1 + position SyntaxError: invalid syntax >>> >>> def while_string_loop (string): position = 0 while(position < len(string)): print(string[position]) position = 1 + position >>> for_string_loop('downward') d o w n w a r d >>> while_string_loop('downward') d o w n w a r d >>> 'hello'[0] 'h' >>> 'hello'[-1] 'o' >>> 'hello'[0:2] 'he' >>> 'hello'[:-1] 'hell' >>> range(5)[0] 0 >>> range(1,5)[0] 1 >>> length('hello') Traceback (most recent call last): File "", line 1, in length('hello') NameError: name 'length' is not defined >>> len('hello') 5 >>> 'hello'[5] Traceback (most recent call last): File "", line 1, in 'hello'[5] IndexError: string index out of range >>> def draw_n_asterisks(n): for current_length in range(n): print('*',end='') >>> draw_n_asterisks(5) ***** >>> def asterisk_triangle(base_size): for current_length in range(1,base_size+1): draw_n_asterisks(current_length) print() >>> asterisk_triangle(5) * ** *** **** ***** >>> def asterisk_triangle2(base_size): for current_length in range(1,base_size+1): for num in range(1,current_length+1): print('*',end='') print() >>> asterisk_triangle2(5) * ** *** **** ***** >>> def asterisk_triangle2(base_size): for current_length in range(1,base_size+1): for num in range(current_length): print('*',end='') print() >>> asterisk_triangle2(5) * ** *** **** ***** >>> def asterisk_triangle2(base_size): for current_length in range(1,base_size+1): for num in range(current_length): print('*',end='') print('end line') print() >>> asterisk_triangle2(5) *end line **end line ***end line ****end line *****end line >>> def asterisk_triangle2(base_size): for current_length in range(1,base_size+1): for num in range(current_length): print('*',end='') ## print('end line') print() >>> asterisk_triangle2(5) * ** *** **** ***** >>> def multiplication_table (high_num): for num1 in range(1, 1+high_num): for num2 in range(1, 1+high_num): print(num1,'X',num2, '=', num1*num2) >>> multiplication_table(5) 1 X 1 = 1 1 X 2 = 2 1 X 3 = 3 1 X 4 = 4 1 X 5 = 5 2 X 1 = 2 2 X 2 = 4 2 X 3 = 6 2 X 4 = 8 2 X 5 = 10 3 X 1 = 3 3 X 2 = 6 3 X 3 = 9 3 X 4 = 12 3 X 5 = 15 4 X 1 = 4 4 X 2 = 8 4 X 3 = 12 4 X 4 = 16 4 X 5 = 20 5 X 1 = 5 5 X 2 = 10 5 X 3 = 15 5 X 4 = 20 5 X 5 = 25 >>> def draw_right_side_up_triangle(base): for number in range(1,base+1): print((base-number)*' ',number*'*',sep='') >>> draw_right_side_up_triangle(3) * ** *** >>> def draw_right_side_up_triangle(base): for number in range(1,base+1): print((base-number)*' ',number*'* ',sep='') >>> draw_right_side_up_triangle(3) * * * * * * >>> draw_right_side_up_triangle(5) * * * * * * * * * * * * * * * >>> draw_right_side_up_triangle(10) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * >>> ================================ RESTART ================================ >>> >>> draw_upside_down_triangle(3) * * * >>> draw_upside_down_triangle(5) * * * * * * * * * * >>> ================================ RESTART ================================ >>> >>> draw_upside_down_triangle(3) * * * >>> ================================ RESTART ================================ >>> >>> draw_upside_down_triangle(3) ** * >>> ================================ RESTART ================================ >>> >>> draw_upside_down_triangle(3) *** ** * >>> ================================ RESTART ================================ >>> >>> draw_upside_down_triangle(3) * * * * * * >>> draw_upside_down_triangle(10) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * >>> draw_hour_glass_or_diamond(5,3,'hr') Traceback (most recent call last): File "", line 1, in draw_hour_glass_or_diamond(5,3,'hr') File "/Users/adam/Desktop/Summer 2011 Scripts/asterisk_triangle_001.py", line 13, in draw_hour_glass_or_diamond for iteration in range(repetitions): NameError: global name 'repetitions' is not defined >>> ================================ RESTART ================================ >>> >>> draw_hour_glass_or_diamond(5,3,'hr') * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * >>> draw_hour_glass_or_diamond(5,3,'diamond') * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * >>> ================================ RESTART ================================ >>> >>> draw_hour_glass_or_diamond(5,3,'diamond') * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * >>> ================================ RESTART ================================ >>> >>> draw_hour_glass_or_diamond(5,3,'diamond') * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * >>> draw_hour_glass_or_diamond(5,3,'hr') * * * * * * * * * * * * * * * Traceback (most recent call last): File "", line 1, in draw_hour_glass_or_diamond(5,3,'hr') File "/Users/adam/Desktop/Summer 2011 Scripts/asterisk_triangle_001.py", line 16, in draw_hour_glass_or_diamond draw_right_side_up_triangle(base_size) TypeError: draw_right_side_up_triangle() takes exactly 2 positional arguments (1 given) >>> ================================ RESTART ================================ >>> >>> draw_hour_glass_or_diamond(5,3,'hr') * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * >>> ================================ RESTART ================================ >>> >>> draw_hour_glass_or_diamond(5,3,'hr') * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * >>> draw_hour_glass_or_diamond(7,5,'hr') * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * >>> ================================ RESTART ================================ >>> >>> draw_hour_glass_or_diamond(7,5,'hr') * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * >>> draw_hour_glass_or_diamond(7,5,'diamond') * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * >>>