Python 3.3.2 (v3.3.2:d047928ae3f6, May 13 2013, 13:52:24) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "copyright", "credits" or "license()" for more information. >>> 2 ** 2 4 >>> 2 ** 6 64 >>> 8/3.0 2.6666666666666665 >>> 8/4.0 2.0 >>> #order of operations - precedence >>> # ** >>> # * / // % >>> # + - >>> 4 + 3 * 2 10 >>> (4 + 3) * 2 14 >>> 8/3.0 2.6666666666666665 >>> 8//3.0 2.0 >>> 2 - 3 -1 >>> 2 - -4 6 # A helpful error message >>> 4/0 Traceback (most recent call last): File "", line 1, in 4/0 ZeroDivisionError: division by zero # An error message that isn't that useful >>> 4 + SyntaxError: invalid syntax >>> help(abs) Help on built-in function abs in module builtins: abs(...) abs(number) -> number Return the absolute value of the argument. >>> type(7) >>> type(2.3) >>> type("hello there") >>> x = 7 >>> type(x) >>> 8e+2 # 8.0 * 10 ** 2 800.0 >>> 8e-2 # 8.0 * 10 ** -2 = 8/100 0.08 >>> int(7.3) 7 >>> int(7.9) 7 >>> int("889") 889 # There isn't a way to map the string "hello" into # an int, so you get an error >>> int("hello") Traceback (most recent call last): File "", line 1, in int("hello") ValueError: invalid literal for int() with base 10: 'hello' >>> float("7") 7.0 >>> # Math versus python >>> #In Math, "p = q + 10" is a statement >>> # that something is true >>> # In Python, that's an assignment statement >>> #x = x + 1 !!!! This makes no sense in Math! >>> x = 3 >>> x 3 >>> x == 3 True >>> x == 4 False yes >>> i = 3 >>> j = 4 >>> # in math these mean the same thing >>> #i = j >>> #j = i # But they do not mean the same thing in Python >>> i = 3 >>> j = 4 >>> i = j >>> j = i >>> i 4 >>> j 4 >>> i = 3 >>> j = 4 >>> j = i >>> i = j >>> i 3 >>> j 3 >>> 6 = j SyntaxError: can't assign to literal >>> "hello" = 4 SyntaxError: can't assign to literal >>> #variables must start with a letter or >>> # underscore # Case matters; x and X are different variables >>> x = 4 >>> X = 3 >>> x 4 >>> X 3 >>> #variable names can include letters, digits and underscore >>> percentage_amount = 3 >>> # We ran program input.py # It gets input from the shell. You can see the run here. # I typed Jan, 1000, and 50 into the python shell enter your name: Jan The type of name is enter the amount of money you have in the bank: 1000 The type of inBank is enter the amount of money you have in stocks: 50 You have 1050 money >>> inBank = "1000" >>> inStocks = "150" # + concatenates (puts together) when it is called # with strings >>> inBank + inStocks '1000150' >>> "hello " + "world" 'hello world' # + does sum when called with ints >>> int(inBank) + int(inStocks) 1150 >>> #Let's look at formatting print statements >>> total = 4700.0 >>> due = total/12 >>> due 391.6666666666667 >>> format(due) '391.6666666666667' >>> format(due,".2f") '391.67' >>> format(due,".4f") '391.6667' >>> print("The monthly payment is",format(due,".2f")) The monthly payment is 391.67 >>> print("The monthly payment is",due) The monthly payment is 391.6666666666667 >>> print("The monthly payment is",format(due,".2f"),sep="") The monthly payment is391.67 >>> print("The monthly payment is",format(due,".2f"),sep="&&&") The monthly payment is&&&391.67 >>> print(1,2,3,sep="*&%") 1*&%2*&%3 >>> total = 1234789 >>> due = total / 12 >>> due 102899.08333333333 >>> print("The monthly payment is",format(due,",.2f")) The monthly payment is 102,899.08 >>> print("The monthly payment is $",format(due,",.2f")) The monthly payment is $ 102,899.08 >>> print("The monthly payment is $",format(due,",.2f"),sep="") # Finally, we get what we want! The monthly payment is $102,899.08 >>> # At the end of the class, we ran the program "columns.py" # You should run the program, and make sure you understand # the output