Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "copyright", "credits" or "license()" for more information. >>> WARNING: The version of Tcl/Tk (8.5.9) in use may be unstable. Visit http://www.python.org/download/mac/tcltk/ for current information. >>> # we have already seen one way to convert between types >>> round(3.75) 4 >>> # casting: changing one type to another explicitly >>> int(3.75) 3 >>> int(-3.75) -3 >>> type(3.75) >>> type(3) >>> >>> float(42) 42.0 >>> type(42.0) >>> >>> type("hello") >>> >>> print("Exchange",i,":") Traceback (most recent call last): File "", line 1, in print("Exchange",i,":") NameError: name 'i' is not defined >>> print("Exchange",3,":") Exchange 3 : >>> print("Exchange" + 3 + ":") Traceback (most recent call last): File "", line 1, in print("Exchange" + 3 + ":") TypeError: Can't convert 'int' object to str implicitly >>> str(3) '3' >>> print("Exchange", str(3) + ":") Exchange 3: >>> >>> str(4.5) '4.5' >>> x = input("Tell me a number: ") Tell me a number: 4 >>> x '4' >>> int(x) 4 >>> >>> # int(), float(), str(), type() >>> >>> # arithmetic operators (+,-,*,/ so far) >>> >>> 5/2 2.5 >>> 5//2 # integer division 2 >>> >>> 5**2 # exponentiation 25 >>> 3**3 # 3^3 27 >>> >>> # mod operator >>> >>> 5 % 2 # what is the remainder when 5 is divided by 2? 1 >>> 17 % 3 2 >>> 5 % 5 0 >>> 15 % 5 0 >>> >>> # sometimes floats with many decimal places produce errors >>> 5.0 - 4.9 0.09999999999999964 >>> >>> >>> math.sqrt(2) Traceback (most recent call last): File "", line 1, in math.sqrt(2) NameError: name 'math' is not defined >>> import math >>> math.sqrt(2) 1.4142135623730951 >>> math.sqrt(25) 5.0 >>> for * in math SyntaxError: invalid syntax >>> from math import * >>> sqrt(2) 1.4142135623730951 >>> # do not do: from math import * (!!) >>> >>> from math import sqrt >>> sqrt(2) 1.4142135623730951 >>> >>> math.pi 3.141592653589793 >>> math.sin(0) 0.0 >>> math.cos(0) 1.0 >>> ================================ RESTART ================================ >>> Enter n = 10 ## >>> ================================ RESTART ================================ >>> Enter n = hello Traceback (most recent call last): File "/Users/ssheehan/Desktop/triangle.py", line 10, in main() File "/Users/ssheehan/Desktop/triangle.py", line 7, in main n = int(input("Enter n = ")) ValueError: invalid literal for int() with base 10: 'hello' >>> ================================ RESTART ================================ >>> Enter n = 10.5 Traceback (most recent call last): File "/Users/ssheehan/Desktop/triangle.py", line 10, in main() File "/Users/ssheehan/Desktop/triangle.py", line 7, in main n = int(input("Enter n = ")) ValueError: invalid literal for int() with base 10: '10.5' >>> ================================ RESTART ================================ >>> Enter n = 10.5 ## >>> ================================ RESTART ================================ >>> Enter n = 4 ## # # # # # # >>> ================================ RESTART ================================ >>> Enter n = 4 ## # # # # # # #### >>> ================================ RESTART ================================ >>> Enter n = 4 ## # # # # # # ###### >>> ================================ RESTART ================================ >>> Enter n = 4 # ## # # # # # # ###### >>> ================================ RESTART ================================ >>> Enter n = 10 # ## # # # # # # # # # # # # # # # # # # ############ >>> ================================ RESTART ================================ >>> Enter n = 35 # ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ##################################### >>>