Midterm No. 1 for V22.0002.005 Wednesday, October 6, 2010
Line Code1. def minus(total,decrement)2 output = total - decrement3. return(output)Line Correction of Error1. need to add colon (:) at end of line2.3.Question 11: This function solicits user input, by querying about some of the user’s personal attributes. It then printsout these attributes in a single sentence. Find 3 errors.Line Code1. def describe intelligent life form():2. height = input(’What is your height in centimeters? ’)3. species = input(’What is your species? ’)4. input(’Are you male or female?’)5. name = input(’What is your name? ’)6. favorite-food = input(’What is your favorite food? ’)7. print(’I see that you are a’, height, ’centimeters tall’, gender \8. ’specimen of the’ species, ’species’)9. print(’and that your favorite food is’, favorite-food+’.’)10. ## Example with user input: 182, male, Adam, chocolate11. ## I see that you are a 182 centimeters tall male specimen of the human species12. ## and your favorite food is chocolate.Line Correction of Error18.104.22.168. no variable is defined5.6. The variable favorite-food contains an illegal character: ’-’7.8.gender is not defined and comma required after gender9. The illegal variable favorite-food is here10.11.12.
Question 12: The length of a person’s foot is claimed to be 15% of their height. This function tests this hypothesisfor one individual. It prints out an informative statement and returns the user’s foot to height ratio. Find 4 errorsLine Code1. def test foot to height ratio():2. print(’This function calculates and records your foot-length to total height ratio.’)3. print(’All measurements should be given in inches if you are Americanor in millimeters if you are from anywhere else in the world.’)4. foot-length=float(input(’Please measure your foot and state its length: ’))5. height=input(float(’Please indicate your total height: ’))6. ratio = foot-length / height7. print(’Thank you for your participation in our study!!!!’)8. print(’Your foot-length to height ratio is: ’, ratio)9. print(’The average foot-length to height ratio may be about .15’)10. print(’Your ratio is ’, (ratio / .15) ’times that ratio’)11. return(ratio)12. ## Example print statements given user input of 11 and 72:13. ## Thank you for your participation in our study!!!!14. ## Your foot-length to height ratio is: 0.152777777777777815. ## The average foot-length to height ratio may be about .1516. ## Your ratio is 1.0185185185185186 times that ratioLine Correction of Error1.2.3. Use Triple Quotes or put a \ before the newline4. foot-length has a -, an illegal character5. input function should contain a string, not a float6. foot-length is an illegal variable22.214.171.124. add comma after second argument of print (ration / .15)126.96.36.199.15.16.