Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> msg = "The value of x is:" >>> x = 15 >>> print(msg, x) The value of x is: 15 >>> print(msg,x) The value of x is: 15 >>> x=15 >>> print(msg,x) The value of x is: 15 >>> total = round(19.973, 2) >>> total 19.97 >>> a = "The total is $" + total + "." Traceback (most recent call last): File "", line 1, in a = "The total is $" + total + "." TypeError: Can't convert 'float' object to str implicitly >>> a = "The total is $" + str(total) + "." >>> print("The total is $", total, '.') The total is $ 19.97 . >>> print(a) The total is $19.97. >>> 'The total is $%.2f.' % (total) 'The total is $19.97.' >>> str_total = format(total, '.2f') >>> type(str_total) >>> a = "The total is $"+total+'.' Traceback (most recent call last): File "", line 1, in a = "The total is $"+total+'.' TypeError: Can't convert 'float' object to str implicitly >>> a = "The total is $"+str_total+'.' >>> print(a) The total is $19.97. >>> b = "My name is Zeus!" >>> b.lower().capitalize() 'My name is zeus!' >>> b 'My name is Zeus!' >>> print(b) My name is Zeus! >>> b.lower() 'my name is zeus!' >>> c = b.lower() >>> c.capitalize() 'My name is zeus!' >>> c = '12345' >>> c.lower() '12345' >>> c.capitalize() '12345' >>> dir() ['__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'a', 'b', 'c', 'msg', 'str_total', 'total', 'x'] >>> dir(b) ['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] >>> print(b) My name is Zeus! >>> b 'My name is Zeus!' >>> b.find('Zeus') 11 >>> b.find('zeus') -1 >>> b.find('ZEUS') -1 >>> c = b.lower() >>> c.find('zeus') 11 >>> c.find('Zeus') -1 >>> c.index('zeus') 11 >>> c.index('Zeus') Traceback (most recent call last): File "", line 1, in c.index('Zeus') ValueError: substring not found >>> c.index.lower() Traceback (most recent call last): File "", line 1, in c.index.lower() AttributeError: 'builtin_function_or_method' object has no attribute 'lower' >>> d = 'Zeus' >>> c.index(d) Traceback (most recent call last): File "", line 1, in c.index(d) ValueError: substring not found >>> c.index('Zeus') Traceback (most recent call last): File "", line 1, in c.index('Zeus') ValueError: substring not found >>> b.find(d.lower()) -1 >>> b 'My name is Zeus!' >>> c 'my name is zeus!' >>> e = d.lower() >>> e 'zeus' >>> c.find(e) 11 >>> c.find(d.lower()) 11 >>> d = 'Zeus' >>> c.find(d.lower()) 11 >>> d = 'ZEUS' >>> c.find(d.lower()) 11 >>> input("Please enter your name: ") Please enter your name: Michael Lipschultz 'Michael Lipschultz' >>> name = input("Please enter your name: ") Please enter your name: Michael Lipschultz >>> name 'Michael Lipschultz' >>> ================================ RESTART ================================ >>> Please enter your name: Michael Your name is Michael The length of your name is: 7 >>> name 'Michael' >>> type(name) >>> number = input("What is your favorite number? ") What is your favorite number? 15 >>> type(number) >>> number = float(number) >>> type(number) >>> number = float(input("What is your favorite number? ")) What is your favorite number? -28.3 >>> type(number) >>> number = float(input("What is your favorite number? ")) What is your favorite number? two Traceback (most recent call last): File "", line 1, in number = float(input("What is your favorite number? ")) ValueError: could not convert string to float: 'two' >>> log10(1000) Traceback (most recent call last): File "", line 1, in log10(1000) NameError: name 'log10' is not defined >>> math.log10(1000) Traceback (most recent call last): File "", line 1, in math.log10(1000) NameError: name 'math' is not defined >>> import math >>> math.log10(1000) 3.0 >>> math.log(1000) 6.907755278982137 >>> math.log(1000, 10) 2.9999999999999996 >>> from math import pow >>> pow(2, 3) 8.0 >>> math.floor(3.4) 3 >>> math.ceil(3.4) 4 >>> ================================ RESTART ================================ >>> Please enter your name: Michael Your name is Michael The length of your name is: 7 >>> name 'Michael' >>> True True >>> False False >>> 15.3 15.3 >>> "This is a string." 'This is a string.' >>> true Traceback (most recent call last): File "", line 1, in true NameError: name 'true' is not defined >>> false Traceback (most recent call last): File "", line 1, in false NameError: name 'false' is not defined >>> x = 5 >>> y =9 >>> x < y True >>> x > y False >>> x <= y True >>> x <= 5 True >>> y >= 9 True >>> 15.0 >= 2 True >>> 1 == 1 True >>> 1 != 0 True >>> x == 5 True >>> x = 5 >>> 1 =! 0 SyntaxError: invalid syntax >>> 5 >= 0 True >>> 5 => 0 SyntaxError: invalid syntax >>> a = 'cat' >>> b = "cat" >>> a == b True >>> b = 'Cat' >>> a == b False >>> b = 'cats' >>> a == b False >>> b = 'tac' >>> a == b False >>> b = 'Cat' >>> a 'cat' >>> a != b True >>> 'cat' < 'Cat' False >>> 'abc' < 'xyz' True >>> 'abc' < 'XYZ' False >>> 19 > 5 True >>> "cat" > "15" True >>> 19 > "15" Traceback (most recent call last): File "", line 1, in 19 > "15" TypeError: unorderable types: int() > str() >>> 19 > "cat" Traceback (most recent call last): File "", line 1, in 19 > "cat" TypeError: unorderable types: int() > str() >>> str(19) '19' >>> str(19) > "15" True >>> 'C' > 15 Traceback (most recent call last): File "", line 1, in 'C' > 15 TypeError: unorderable types: str() > int() >>> ord('C') 67 >>> ord('C') > 19 True >>> 'C' > "15" True >>> ord('15') Traceback (most recent call last): File "", line 1, in ord('15') TypeError: ord() expected a character, but string of length 2 found >>> ord('1'), ord('5') (49, 53) >>> int('15') 15 >>> math.log10(1000) Traceback (most recent call last): File "", line 1, in math.log10(1000) NameError: name 'math' is not defined >>> import math >>> math.log10(1000) 3.0 >>> math.log(1000, 10) 2.9999999999999996 >>> x = 9.3 / 7.8 >>> y = (10*9.3) / (10*7.8) >>> x == y False >>> x 1.1923076923076925 >>> y 1.1923076923076923 >>> z = 15.0 >>> a = 3*5.0 >>> a == z True >>> abs(-15) 15 >>> abs(x) 1.1923076923076925 >>> abs(x-y) 2.220446049250313e-16 >>> THRESHOLD = 0.0000000001 >>> abs(x-y) < THRESHOLD True >>> THRESHOLD 1e-10 >>> THRESHOLD = 1 >>> THRESHOLD 1 >>> math.PI Traceback (most recent call last): File "", line 1, in math.PI AttributeError: 'module' object has no attribute 'PI' >>> math.pi 3.141592653589793 >>> math.pi = 3 >>> math.pi 3 >>> a = "My name is Zeus!" >>> a.beginswith('My') Traceback (most recent call last): File "", line 1, in a.beginswith('My') AttributeError: 'str' object has no attribute 'beginswith' >>> a.beginwith('My') Traceback (most recent call last): File "", line 1, in a.beginwith('My') AttributeError: 'str' object has no attribute 'beginwith' >>> dir(a) ['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] >>> a.startswith('My') True >>> a 'My name is Zeus!' >>> a.startswith('my') False >>> a.startswith('y') False >>> a.endswith('Zeus') False >>> a.endswith('Zeus!') True >>> a.endswith('!') True >>> a.startswith('My ') True >>> a.startswith('Myn') False >>> len(a) 16 >>> len(a) < 20 True >>>