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. >>> ================================ RESTART ================================ >>> >>> question_6() Your change is: 2.0 quarters 1.0 dimes 1.0 nickels 1.0 pennies >>> ================================ RESTART ================================ >>> >>> question_6() Your change is: 2 quarters 1 dimes 1 nickels 1 pennies >>> 5.0//2 2.0 >>> 5//2 2 >>> ================================ RESTART ================================ >>> >>> output = vending_machine(5.00,4.34) Your change is: 2 quarters 1 dimes 1 nickels 1 pennies >>> output >>> output == None True >>> None >>> question10() Traceback (most recent call last): File "", line 1, in question10() NameError: name 'question10' is not defined >>> question10_() Traceback (most recent call last): File "", line 1, in question10_() NameError: name 'question10_' is not defined >>> question_10() This program can figure out how much fabric you need to make a dog sweater. Please take out a tape measure and provide the requested information in inches. What is the distance from the base of the dog's neck to the base ot its tail? 2.5 What is the height of the thickest portion of the dog's chest? 1 You need 9.42477796077 square inches of fabric to make a sweater for your dog. >>> question_10() This program can figure out how much fabric you need to make a dog sweater. Please take out a tape measure and provide the requested information in inches. What is the distance from the base of the dog's neck to the base ot its tail? 30 What is the height of the thickest portion of the dog's chest? 12 You need 1357.16802635 square inches of fabric to make a sweater for your dog. >>> 1360**.5 36.87817782917155 >>> ================================ RESTART ================================ >>> >>> center_3_sentences() This program will center 3 lines of text that you provide What is the first line (no more than 65 characters): Hello World! What is the second line (no more than 65 characters): Welcome to NYU! What is the third line (no more than 65 characters): What is your favorite color? Hello World! Welcome to NYU! What is your favorite color? >>> ================================ RESTART ================================ >>> >>> question_11() This program will center 3 lines of text that you provide What is the first line (no more than 65 characters): Traceback (most recent call last): File "", line 1, in question_11() File "/Users/adam/Desktop/summer-sample-midterm/sample-midterm.py", line 179, in question_11 center_3_sentences() File "/Users/adam/Desktop/summer-sample-midterm/sample-midterm.py", line 168, in center_3_sentences sentence1 = input('What is the first line (no more than 65 characters): ') KeyboardInterrupt >>> question_12() This program determines how nice you really are according to the guidelines of the World Council on Niceness (WCN). A final score will be provided in Standard Niceness Units (SNUs) Please answer the following question "yes" or "no". Do you always share your candy? yes Please answer the following question "yes" or "no". Do you clean up after yourself most of the time? yes Please answer the following question "yes" or "no". Do you give money to charity? yes Please answer the following question "yes" or "no". Do you spend some of your time doing charitable work? yes Please answer the following question "yes" or "no". Do you care about non-human animals? yes Please answer the following question "yes" or "no". Would you commit a crime against another person for personal gain? no Please answer the following question "yes" or "no". Do you always share your food? no Please answer the following question "yes" or "no". Do you clean up after other people? yes Please answer the following question "yes" or "no". Would you give up all your money to help a friend in serious need? yes Please answer the following question "yes" or "no". Would you do the same for a stranger? no Please answer the following question "yes" or "no". Would you dedicate your life to a charitable cause and be poor yourself? yes Please answer the following question "yes" or "no". Do you believe in eating all non-human animals? no Please answer the following question "yes" or "no". Do you believe in eating some non-human animals? yes Your current niceness is: 80 Standard Niceness Units >>> def print_date(month,day,year): print('Month =',month) print('Day =',day) print('Year =',year) return(str(month)+' '+str(day)+', '+str(year)) >>> print_date('January',3,2011) Month = January Day = 3 Year = 2011 'January 3, 2011' >>> def print_date2(month,day,year): print('Month =',month) print('Day =',day) print('Year =',year) return(month+' '+day+', '+year) >>> def surround_string_with_numbers(string): import random output = '' for character in string: number = math.floor(10*random.random()) output = output+character+str(number) return(output) >>> surround_string_with_numbers('hello') Traceback (most recent call last): File "", line 1, in surround_string_with_numbers('hello') File "", line 5, in surround_string_with_numbers number = math.floor(10*random.random()) NameError: global name 'math' is not defined >>> def surround_string_with_numbers(string): import random import math output = '' for character in string: number = math.floor(10*random.random()) output = output+character+str(number) return(output) >>> surround_string_with_numbers('hello') 'h5e2l4l0o5' >>> surround_string_with_numbers('Pickle') 'P1i5c8k3l1e0' >>> def surround_string_with_numbers(string): import random import math output = '' for character in string: number = math.floor(10*random.random()) output = output+character+str(number) print('number:',number,'character:',character,'output:',output) return(output) >>> surround_string_with_numbers('Pickle') number: 5 character: P output: P5 number: 5 character: i output: P5i5 number: 3 character: c output: P5i5c3 number: 0 character: k output: P5i5c3k0 number: 7 character: l output: P5i5c3k0l7 number: 3 character: e output: P5i5c3k0l7e3 'P5i5c3k0l7e3' >>> def surround_string_with_numbers(string): import random import math output = '' for character in string: number = math.floor(10*random.random()) output = output+character+str(number) ## print('number:',number,'character:',character,'output:',output) return(output) >>> def calculate_triangle_number(number): output = 0 for num in range(1,number+1): output = output + num return(output) >>> calculate_triangle_number(5) 15 >>> def calculate_triangle_number(number): output = 0 for num in range(1,number+1): output = output + num print('num:',num,'output:',output) return(output) >>> calculate_triangle_number(5) num: 1 output: 1 num: 2 output: 3 num: 3 output: 6 num: 4 output: 10 num: 5 output: 15 15 >>> range(6) range(0, 6) >>> len(range(6)) 6 >>> range(1,6) range(1, 6) >>> len(range(1,6)) 5 >>> range(6)[1,6] Traceback (most recent call last): File "", line 1, in range(6)[1,6] TypeError: sequence index must be integer, not 'tuple' >>> range(6)[1:6] Traceback (most recent call last): File "", line 1, in range(6)[1:6] TypeError: sequence index must be integer, not 'slice' >>> range(1,6) range(1, 6) >>> [0,1,2,3,4,5,6][1:6] [1, 2, 3, 4, 5] >>> [0,1,2,3,4,5][1:6] [1, 2, 3, 4, 5] >>> dog_sweater() This program can figure out how much fabric you need to make a dog sweater. Please take out a tape measure and provide the requested information in inches. What is the distance from the base of the dog's neck to the base ot its tail? 30 What is the height of the thickest portion of the dog's chest? 12 You need 1357.16802635 square inches of fabric to make a sweater for your dog. 1357.1680263507903 >>> def two_character_rectangle(height,char1,char2): width = 1+height for number in range(height): print(char1*(number+1),char2*(height-number),sep='') >>> two_character_rectangle(4,'*','%') *%%%% **%%% ***%% ****% >>> def two_character_rectangle(height,char1,char2): for number in range(height): print(char1*(number+1),char2*(height-number),sep='') >>> print('hello','world') hello world >>> print('hello','world',sep='') helloworld >>> print('hello','world',sep='*') hello*world >>> print('hello','world') hello world >>> def print_2_things(thing1,thing2): print(thing1) print(thing2) >>> print_2_things('hello','there') hello there >>> def print_2_things(thing1,thing2): print(thing1,end=' ') print(thing2) >>> print_2_things('hello','there') hello there >>> def print_2_things(thing1,thing2): print(thing1,end='') print(thing2) >>> print_2_things('hello','there') hellothere >>> def two_character_rectangle(height,char1,char2): for number in range(height): print(char1*(number+1),char2*(height-number)) >>> two_character_rectangle(5,'X','O') X OOOOO XX OOOO XXX OOO XXXX OO XXXXX O >>> def two_character_rectangle(height,char1,char2): for number in range(height): print(char1*(number+1),char2*(height-number),sep='') >>> two_character_rectangle(5,'X','O') XOOOOO XXOOOO XXXOOO XXXXOO XXXXXO >>> print('hello',end='\n') hello >>> print('hello') hello >>> def two_character_rectangle2(height,char1,char2): for number in range(height): print(char1*number,char2*(height-(number+1)),sep='') >>> two_character_rectangle2(5,'X','O') OOOO XOOO XXOO XXXO XXXX >>> ================================ RESTART ================================ >>> >>> my_turtle.heading() 0.0 >>> my_turtle.left(50) >>> my_turtle.heading() 50.0 >>> my_turtle.home() >>> ================================ RESTART ================================ >>> >>> draw_stick_figure() >>> ================================ RESTART ================================ >>> >>> draw_stick_figure() Traceback (most recent call last): File "", line 1, in draw_stick_figure() File "/Users/adam/Desktop/Summer 2011 Scripts/stickfigure.py", line 19, in draw_stick_figure my_turlte.pd() NameError: global name 'my_turlte' is not defined >>> ================================ RESTART ================================ >>> >>> draw_stick_figure() >>> ================================ RESTART ================================ >>> >>> draw_stick_figure() >>> range(5,10)[0] 5 >>> range(5,10)[9] Traceback (most recent call last): File "", line 1, in range(5,10)[9] IndexError: range object index out of range >>> range(5,10)[4] 9 >>> range(5,10)[5] Traceback (most recent call last): File "", line 1, in range(5,10)[5] IndexError: range object index out of range >>> 'hello'[-1] 'o' >>> 'hello'[-1:] 'o' >>> 'hello'[-2:] 'lo' >>>