Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Name: James Taylor-Bye
- # Section: MechanicalMooc Week 1
- # Date: 19/06/13
- # hw1.py
- blank = " " # A blank line used for formatting
- ##### Template for Homework 1, exercises 1.2-1.5 ######
- print "********** Exercise 1.2 **********"
- print " | | "
- print " ----------------"
- print " | | "
- print "-----------------"
- print " | | "
- print "********** Exercise 1.3 **********"
- print blank * 2
- a = " | | "
- b = "-----------------"
- print a
- print b
- print a
- print b
- print a
- print blank
- print "********** Exercise 1.4 **********"
- print "********* Part II *************"
- import math
- print blank
- print "Question 1"
- print blank
- print "The numerator is the result of 3 * 5 "
- print "The denominator is the result of 2 + 3 "
- numerator = 3 * 5
- denominator = 2 + 3
- print "So the answer is : " + str(numerator) + "/" + str (denominator)
- print blank
- print "Question 2"
- print blank
- x = 7 + 9
- print"7 + 9 = " + str (x)
- y = math.sqrt (x)
- print "Sqrt of 16 = " + str (y)
- z = y * 2
- print "The answer of 16 * 2 " + str (z)
- print blank
- print "Question 3"
- print blank
- t = 4 - 7
- print "4 - 7 = " + str(t)
- r = t ** 3 # Times the result by itself 3 times
- print str (t) + " times by itself 3 times = " + str (r)
- print blank
- print "Question 4"
- print blank
- s = -19 + 100
- print "-19 + 100 = " + str(s)
- w = math.sqrt (s)
- c = math.sqrt (w)
- print "so the 4th Root of " +str (s) + " is " + str (c)
- print blank
- print "Question 4"
- rem = 6 % 4
- print "The remainder or modulus of 6 % 4 = " + str (rem)
- print "Not implemented" # Delete this line when you write your code!
- print "********* Part III *************"
- print blank
- result1 = 2 + 3 / 4 * 5
- print "2 + 3 / 4 * 5 = " + str (result1)
- result2 = (2 + 3 ) / 4 * 5
- print "(2 + 3 ) / 4 * 5 = " +str (result2)
- print """The parentheses in the second example are evaluated 1st instead
- of the multiplication in the first example producing different outputs."""
- # """ Says that this print line is over more than one line.
- print blank
- print "********** Exercise 1.5 **********"
- print "Not implemented" # Delete this line when you write your code!
- print blank
- ''' ********** Exercise 1.9 ***********
- 1. and is not legal as its a keyword for python used in boolean calcs
- 2. _and is legal
- 3. var is legal
- 4. var1 is legal
- 5. 1var is not legal as it starts with a number
- 6. my-name is not legal as it contains a -
- 7. your_name is legal
- 8. COLOR is legal though bad form
- ******** Exercise 1.10 ********
- 1. a = False is type bool
- 2. b = 3.7 is type float
- 3. c = "Alex" is type string
- 4. d = 7 is type int
- 5. e = "True" is type string
- 6. f = 17 is type int
- 7. g = "17" is type string
- 8. h = True is type bool
- 9. i = "3.14159" is type string
- ********** Exercise 1.11 ********
- 1. A girl sees a boy on a hill who has a telescope.
- 2. A girl is looking through a telescope at the boy on the hill.
- 3. (A) = Alice sees the boy on the hill looking through his telescope.
- (B) = Alice, looking through her telescope, sees the boy on the hill.
- ********* Exercise 1.12 *********
- 1. b and c = False
- 2. b or c = True
- 3. not a and b = True
- 4. (a and b) or not c = True
- 5. not b and not (a or c) = False
- '''
Advertisement
Add Comment
Please, Sign In to add comment