You are on page 1of 4

# Python Lesson 1 : Introduction to Programming with Python outline IDE : Pyscripter print(3+7) print(2-1) print(this is a chunk of text) print(type(3+7))

print(type(this is a chunk of text) a = 3 b = a c = a print + 5 * a a - 1 * b (c) 440 10 1 this is a chunk of text <type int> <type str>

a = -6 b = a * a a - 1 c = a * b if(a<0): print(a<0) print(c) else: print(a is not less than 0) print(c-a) print(we are done with the program) Lesson 2: Binary numbers Base 10 Digits: {0,1,2,3,4,5,6,7,8,9} Hundreds, tens, ones E.g. 1,2,3,4,5,6,7,8,9,10,11

## a<0 -246 we are done with the program

Base 2 (0,1) Digits: {0,1} Eights, Fours, Twos, Ones E.g. 0,1,10,11 Ex: 1010 (Base 2) = 10 (Base 10) (1-eight + 0-fours + 1-twos + 0-ones)

Lesson 3: List of Python >>> a = [1, 2, -1, 9, 11] >>> print a [1,2,-7,9,11] >>> a[1]=sals string >>> print a [1, sals string, -7, 9, 11] >>> b= a >>> print b [1, sals string, -7, 9, 11] >>>c = a[:] >>> print c [1, sals string, -7, 9, 11]

>>>b[0]=0 >>> print b [0, sals string, -7, 9, 11] >>> print a [0, sals string, -7, 9, 11] >>> print c [1, sals string, -7, 9, 11] >>>a [0, sals string, -7, 9, 11] >>> a.append(new element) >>> a [0, sals string, -7, 9, 11], new element] >>>b [0, sals string, -7, 9, 11], new element] >>>c [1, sals string, -7, 9, 11] Lesson 4: For Loops in Python >>> [0, >>> [0, >>> [1, >>> [0, >>> [3, range(6) 1, 2, 3, 4, 5] range(7) 1, 2, 3, 4, 5, 6] range(1, 7) #include, up to but not include 2, 3, 4, 5, 6] range(0, 8, 2) 2, 4, 6] range(3, 31, 3) 6, 9, 12, 15, 18, 21, 24, 27, 30] 0 1 2 3 4 0 1 3 4 10 15 21 28 36 45

## sum = 0 for i in range(10): sum = sum + i print sum

Lesson 5: While Loops in Python # This while loop calculates the sum of 0 through 9 (including 9) and places # it in the variable sum sum = 0 i = 0 while i<10: sum = sum + i 0 1 3 4 10 15 21

print sum i = i + 1 #for I in range(10): # sum = sum + i # print sum Lesson 6: Fun with strings a = My first test string b = Another test string that I have defined c = This is Sals string d = My favourite word is asparagus, what is yours? math_string = 3+4*2 expression_string = a+ +b+ tiger

28 36 45

>>> a My first test string >>> len(a) 20 >>> len(math_string) 5 >>> a_with_b = a+b >>> a_with_b Myfirst test stringAnother test string that I have defined >>> b_with_a = b+a >>> b_with_a Another test string >>> math_string+expression_string 3+4*2a++b+ tiger >>> b.split( ) [Another, test, string, that, I, have, defined] >>> b.split(t) [Ano, her, es, s, ring, ha, I have defined] >>> math_string.find(*) 3 >>> math_string.find(3) 0 >>> c.replace(i, o) Thos os Sals strong >>> c = c.replace(i, o) >>> c Thos os Sals strong >>> math_string 3+4*2 >>> eval(math_string) 11 >>> eval(math_string+ 1) 3+4*21 87 >>> eval(expression_string) My first test string Another test string that I have defined tiger

Lesson 7: Writing a Simple Factorial Program using Python 2 number = input(Enter a non-negative integer to take the factorial of: ) product = 1 for i in range(number): product = product * (i+1) print(product) >>>3 6 >>>10 3628800

Lesson 8: Stepping Through the Factorial Program number = input(Enter a non-negative integer to take the factorial of: ) product = 1 for i in range(number): product = product * (i+1) print(product)