Python 3.2.5 (default, May 15 2013, 23:07:10) [MSC v.1500 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. #types >>> x = 5 >>> type(x) >>> y = 3.14 >>> type(y) >>> s = "michal" >>> type(s) >>> type(True) >>> type("4") >>> type(4.0) # operators >>> 10/3 3.3333333333333335 >>> 10/2 5.0 >>> 10//3 3 >>> 10.0//3 3.0 >>> 4 + 5.0 9.0 >>> 2**0.5 1.4142135623730951 >>> 10%2 0 >>> "4"+"5" '45' >>> "4"*5 '44444' >>> "4"*5.0 Traceback (most recent call last): File "", line 1, in "4"*5.0 TypeError: can't multiply sequence by non-int of type 'float' >>> "4"*0 '' >>> 3 < 4 True >>> 3 <4 and 3> 4 False >>> not 3<4 False #retrieving the rightmost digit of an integer >>> x = 345 >>> x%10 5 >>> (x%100)//10 4 >>> (x//10)%10 4 #conversions between types >>> int("4") 4 >>> float("3.14") 3.14 >>> x = float("2.0") >>> x 2.0 >>> type(x) >>> int(3.45) 3 >>> int ("3a") Traceback (most recent call last): File "", line 1, in int ("3a") ValueError: invalid literal for int() with base 10: '3a' >>> str(56) '56' >>> #conditionals >>> ================================ RESTART ================================ >>> Recitation today! great! Arctic monkeys >>> ================================ RESTART ================================ >>> Recitation today! great! Arctic monkeys #python's input() function >>> >>> s = input("fdsfjdslkfjdslk") fdsfjdslkfjdslk765439k9 >>> s '765439k9' >>> s = input("enter a number") enter a number6 >>> s '6' >>> int(s) 6 #counting the number of zeros in an integer >>> ================================ RESTART ================================ >>> This program will tell you how many 0's are in an integer Please enter an integer: fsdfskd Traceback (most recent call last): File "C:/Personal/Teaching/CS-intro/2017a/recitations/1/cnt_zeros_2.py", line 2, in orig_num = int(input("Please enter an integer: ")) ValueError: invalid literal for int() with base 10: 'fsdfskd' >>> ================================ RESTART ================================ >>> This program will tell you how many 0's are in an integer Please enter an integer: 100 100 has 2 0s >>> ================================ RESTART ================================ >>> This program will tell you how many 0's are in an integer Please enter an integer: 0 0 has 0 0s >>> ================================ RESTART ================================ >>> This program will tell you how many 0's are in an integer Please enter an integer: 0 0 has 1 0s >>> ================================ RESTART ================================ >>> This program will tell you how many 0's are in an integer Please enter an integer: -10 -10 has 0 0s >>> -50//10 -5 >>> ================================ RESTART ================================ >>> This program will tell you how many 0's are in an integer Please enter an integer: -10 Traceback (most recent call last): File "C:/Personal/Teaching/CS-intro/2017a/recitations/1/cnt_zeros_2.py", line 12, in num = num//10 #num//=10 KeyboardInterrupt >>> ================================ RESTART ================================ >>> This program will tell you how many 0's are in an integer Please enter an integer: -10 -1 -1 ... -1 -1 -1Traceback (most recent call last): File "C:/Personal/Teaching/CS-intro/2017a/recitations/1/cnt_zeros_2.py", line 13, in print(num) File "C:\Python32\lib\idlelib\PyShell.py", line 1289, in write return self.shell.write(s, self.tags) KeyboardInterrupt #testing a "for" loop >>> for c in "michal": print(c*4) print(type(c)) mmmm iiii cccc hhhh aaaa llll >>> print ("hi") hi >>> for c in "michal": print(c*4) print(type(c)) c = 5 print(c) mmmm 5 iiii 5 cccc 5 hhhh 5 aaaa 5 llll 5 >>> ================================ RESTART ================================ >>> This program will tell you how many 0's are in an integer Please enter an integer: 0 0 has 1 0s 0 has 1 0s >>> ================================ RESTART ================================ >>> This program will tell you how many 0's are in an integer Please enter an integer: 10.5 Traceback (most recent call last): File "C:/Personal/Teaching/CS-intro/2017a/recitations/1/cnt_zeros_2.py", line 3, in orig_num = int(num_str) ValueError: invalid literal for int() with base 10: '10.5' >>>