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 print_my_name(my_name): print(my_name) >>> my_name = 'Adam' >>> my_name 'Adam' >>> print_my_name('Adam Meyers') Adam Meyers >>> my_name 'Adam' >>> def print_my_name(name): my_name = name print(my_name) >>> print_my_name('Adam Meyers') Adam Meyers >>> my_name 'Adam' >>> def print_my_name(name): global my_name my_name = name print(my_name) >>> print_my_name('Adam Meyers') Adam Meyers >>> my_name 'Adam Meyers' >>> def add_two_numbers(num1,num2): return(num1+num2) >>> output = add_two_numbers(5,4) >>> output 9 >>> def switch_variable_values (variable1, variable2): place_holder = variable1 variable1 = variable2 variable2 = place_holder >>> output = 5 >>> other_output = 7 >>> switch_variable_values(output,other_output) >>> output 5 >>> other_output 7 >>> switch_variable_values(5,7) >>> def print_3_times_on_3_lines(item): print(item,item,item) print(item,item,item) print(item,item,item) >>> print_3_times_on_3_lines(5) 5 5 5 5 5 5 5 5 5 >>> print(5,5,5,sep='') 555 >>> '555' '555' >>> '57hv889' '57hv889' >>> '' '' >>> print(5,5,5,sep='***') 5***5***5 >>> def print_3_times_on_3_lines_with_asterisks(item): print(item,item,item,sep='*') print(item,item,item,sep='*') print(item,item,item,sep='*') >>> print_3_times_on_3_lines_with_asterisks(5) 5*5*5 5*5*5 5*5*5 >>> def print_3_times_on_3_lines_with_asterisks(item): print(item,item,item,sep='*',end='*') print(item,item,item,sep='*',end='*') print(item,item,item,sep='*',end='*') >>> print_3_times_on_3_lines_with_asterisks(5) 5*5*5*5*5*5*5*5*5* >>> def print_date(month,day,year=2011): print(month, str(day)+',', year) >>> print_date('May',25) May 25, 2011 >>> print_date('May',25,year='2000') May 25, 2000 >>> for number in range(5): print(number) 0 1 2 3 4 >>> number 4 >>> def fancy_print(word): print('*',end='') for character in word: print(character,end='*') >>> fancy_print('Hello') *H*e*l*l*o* >>> for time in range(5): print('hello') hello hello hello hello hello >>> for item in [4,'abc',57,[8,9]]: print(item) 4 abc 57 [8, 9] >>> def fancy_print(word): print('*',end='') for gorilla in word: print(character,end='*') >>> fancy_print('hello') *Traceback (most recent call last): File "", line 1, in fancy_print('hello') File "", line 4, in fancy_print print(character,end='*') NameError: global name 'character' is not defined >>> def fancy_print(word): print('*',end='') for gorilla in word: print(gorilla,end='*') >>> fancy_print('hello') *h*e*l*l*o* >>> def fancy_print(word): print('*',end='') for gorilla in word: print(gorilla,end='*') >>> total = 0 >>> for number in range(1,6): total = total + number >>> total 15 >>> total = 0 >>> range(6) range(0, 6) >>> [1,2,3,4,5] [1, 2, 3, 4, 5] >>> for number in range(1,6): print('number:', number,'total:',total) total = total + number print(total) number: 1 total: 0 1 number: 2 total: 1 3 number: 3 total: 3 6 number: 4 total: 6 10 number: 5 total: 10 15 >>> for number in range(1,6): ## print('number:', number,'total:',total) total = total + number ## print(total) >>> total = 0 >>> for number in range(1,6): ## print('number:', number,'total:',total) total = total + number ## print(total) >>> total 15 >>> def put_stars_around_letters (word): output = '*' for letter in word: output = output+letter+'*' return(output) >>> output = put_stars_around_letters('hello') >>> output '*h*e*l*l*o*' >>> def put_stars_around_letters (word): output = '*' for letter in word: print('output so far:',output,'next letter:',letter) output = output+letter+'*' return(output) >>> output = put_stars_around_letters('hello') output so far: * next letter: h output so far: *h* next letter: e output so far: *h*e* next letter: l output so far: *h*e*l* next letter: l output so far: *h*e*l*l* next letter: o >>> output '*h*e*l*l*o*' >>> ================================ RESTART ================================ >>> >>> ================================ RESTART ================================ >>> >>> my_function_with_a_bug(5) 5 >>> ================================ RESTART ================================ >>> >>> ================================ RESTART ================================ >>> output = input('Give me a number: ') Give me a number: 57 >>> output '57' >>> def plus(num1,num2): return(5+5) >>> def super_plus(num1,num2,num3): output = 1 for num in range(num3): output = output + num1 + num2 return(output) >>> def super_plus(num1,num2,num3): output = 1 for num in range(num3): output = output + plus(num1,num2) return(output) >>> super_plus(5,5,3) 31 >>> def interactive_plus(): num1 = int(input('give me a number: ')) num2 = int(input('give me another number: ')) return(num1+num2) >>> interactive_plus() give me a number: 5 give me another number: 7 12 >>> ================================ RESTART ================================ >>> >>> average_5_numbers() Give me a number: 10 Give me another number: 20 Give me another number: 30 Give me another number: 47 Give me another number: 3 22.0 >>> input('say something') say somethingbanana 'banana' >>> ================================ RESTART ================================ >>> >>> output = average_5_numbers() Give me a number: 10 Give me another number: 20 Give me another number: 30 Give me another number: 47 Give me another number: 3 The answer is 22.0 >>> output 22.0 >>> ================================ RESTART ================================ >>> >>> output = average_some_numbers() How many numbers do you want to average5 Give me another number 10 Give me another number 20 Give me another number 30 Give me another number 47 Give me another number 3 The answer is 22.0 >>> ================================ RESTART ================================ >>> >>> (20 * 365)+5+31+28+31+30+26 7451 >>> calculate_bio_rhythm() How many days have you been alive? 7451 Your physical cycle is: -7.93464634821e-14 Your emotional cycle is: -6.5177452146e-14 Your intellectual cycle is: -5.53020806088e-14 Your intuitive cycle is: -4.8025491055e-14 >>> ================================ RESTART ================================ >>> >>> calculate_bio_rhythm() How many days have you been alive? 7451 Your physical cycle is: -1.53976172637e-14 Your emotional cycle is: -1.26480427524e-14 Your intellectual cycle is: -1.07316726384e-14 Your intuitive cycle is: -9.3196104491e-15 >>> ================================ RESTART ================================ >>> >>> calculate_bio_rhythm() How many days have you been alive? 7451 Your physical cycle is: -0.269796771157 Your emotional cycle is: 0.623489801859 Your intellectual cycle is: -0.971811568324 Your intuitive cycle is: 0.475947393037 >>> calculate_bio_rhythm() How many days have you been alive? 7481 Your physical cycle is: 0.997668769191 Your emotional cycle is: 0.900968867902 Your intellectual cycle is: -0.945000818715 Your intuitive cycle is: -0.735723910673 >>> calculate_bio_rhythm() How many days have you been alive? 7541 Your physical cycle is: -0.730835964278 Your emotional cycle is: 0.900968867902 Your intellectual cycle is: -0.0950560433042 Your intuitive cycle is: 0.324699469205 >>>