JTB1979

MechanicalMooc Week 1

Jun 19th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.32 KB | None | 0 0
  1. # Name: James Taylor-Bye
  2. # Section: MechanicalMooc Week 1
  3. # Date: 19/06/13
  4. # hw1.py
  5.  
  6. blank = " " # A blank line used for formatting
  7. ##### Template for Homework 1, exercises 1.2-1.5 ######
  8.  
  9. print "********** Exercise 1.2 **********"
  10.  
  11. print "     |     |     "
  12. print " ----------------"
  13. print "     |     |     "
  14. print "-----------------"
  15. print "     |     |     "
  16.  
  17.  
  18.  
  19. print "********** Exercise 1.3 **********"
  20. print blank * 2
  21.  
  22. a = "     |     |     "
  23. b = "-----------------"
  24.  
  25. print a
  26. print b
  27. print a
  28. print b
  29. print a
  30.  
  31.  
  32.  
  33. print blank
  34. print "********** Exercise 1.4 **********"
  35. print "********* Part II *************"
  36.  
  37. import math
  38.  
  39. print blank
  40. print "Question 1"
  41. print blank
  42. print "The numerator is the result of 3 * 5 "
  43. print "The denominator is the result of 2 + 3 "
  44.  
  45. numerator = 3 * 5
  46. denominator = 2 + 3
  47. print "So the answer is : " + str(numerator) + "/" +  str (denominator)
  48. print blank
  49.  
  50. print "Question 2"
  51. print blank
  52. x = 7 + 9
  53. print"7 + 9 = " + str (x)
  54. y = math.sqrt (x)
  55. print "Sqrt of 16 = " + str (y)
  56. z = y * 2
  57. print "The answer of 16 * 2 " + str (z)
  58. print blank
  59.  
  60. print "Question 3"
  61. print blank
  62. t = 4 - 7
  63. print "4 - 7 = " + str(t)
  64. r = t ** 3 # Times the result by itself 3 times
  65. print str (t) + " times by itself 3 times = " + str (r)
  66. print blank
  67.  
  68. print "Question 4"
  69. print blank
  70. s = -19 + 100
  71. print "-19 + 100 = " + str(s)
  72. w = math.sqrt (s)
  73. c = math.sqrt (w)
  74. print "so the 4th Root of " +str (s) + " is " + str (c)
  75. print blank
  76.  
  77. print "Question 4"
  78.  
  79. rem = 6 % 4
  80. print "The remainder or modulus of 6 % 4 = " + str (rem)
  81. print "Not implemented" # Delete this line when you write your code!
  82.  
  83. print "********* Part III *************"
  84. print blank
  85. result1 = 2 + 3 / 4 * 5
  86. print "2 + 3 / 4 * 5 = " + str (result1)
  87. result2 = (2 + 3 ) / 4 * 5
  88. print "(2 + 3 ) / 4 * 5 = " +str (result2)
  89. print """The parentheses in the second example are evaluated 1st instead
  90. of the multiplication in the first example producing different outputs."""
  91. # """ Says that this print line is over more than one line.
  92. print blank
  93.  
  94.  
  95. print "********** Exercise 1.5 **********"
  96. print "Not implemented" # Delete this line when you write your code!
  97. print blank
  98.  
  99.  
  100. ''' ********** Exercise 1.9 ***********
  101.   1. and is not legal as its a keyword for python used in boolean calcs
  102.   2. _and is legal
  103.   3. var is legal
  104.   4. var1 is legal
  105.   5. 1var is not legal as it starts with a number
  106.   6. my-name is not legal as it contains a -
  107.   7. your_name is legal
  108.   8. COLOR is legal though bad form
  109.  
  110.   ******** Exercise 1.10 ********
  111.   1. a = False is type bool
  112.   2. b = 3.7 is type float
  113.   3. c = "Alex" is type string
  114.   4. d = 7 is type int
  115.   5. e = "True" is type string
  116.   6. f = 17 is type int
  117.   7. g = "17" is type string
  118.   8. h = True is type bool
  119.   9. i = "3.14159" is type string
  120.  
  121.  
  122.   ********** Exercise 1.11 ********
  123.   1. A girl sees a boy on a hill who has a telescope.
  124.   2. A girl is looking through a telescope at the boy on the hill.
  125.   3. (A) = Alice sees the boy on the hill looking through his telescope.
  126.      (B) = Alice, looking through her telescope, sees the boy on the hill.
  127.  
  128.   ********* Exercise 1.12 *********
  129.  
  130.   1. b and c = False
  131.   2. b or c = True
  132.   3. not a and b = True
  133.   4. (a and b) or not c = True
  134.   5. not b and not (a or c) = False
  135.  
  136.  
  137.   '''
Advertisement
Add Comment
Please, Sign In to add comment