MIT_6001
文章平均质量分 79
sunner008
这个作者很懒,什么都没留下…
展开
-
Lecture 2: Operators and operands; statements; branching, conditionals, and iteration
# sample code for use in Lecture 2, Fall 2008x = 3x=x*xn = input('Enter a number:')print (n)x = 15if (x/2)*2 == x: print ('even')else: print ('odd')z = 'b'if 'x'<z: print ('Hello')原创 2017-09-25 00:06:04 · 177 阅读 · 0 评论 -
Lecture 10: Divide and conquer methods, merge sort, exceptions
# Lecture 10 fall 2008def merge(left,right): result = [] i,j = 0, 0 while i < len(left) and j < len(right): if left[i] <= right[j]: result.append(left[i])原创 2017-09-25 00:35:17 · 226 阅读 · 0 评论 -
Lecture 9: Binary search, bubble and selection sorts
# Lecture 9 fall 2008def bsearch(s, e, first, last, calls): print (first, last, calls) if (last - first) < 2: return s[first] == e or s[last] == e mid = first + (last - first)//2原创 2017-09-25 00:25:31 · 163 阅读 · 0 评论 -
Lecture 8: Complexity; log, linear, quadratic, exponential algorithms
# code file for lecture 8, 2008 fall#interative exponentdef exp1(a,b): ans = 1# Initiation ans(two more step) while (b>0):#Step1: comparsion ans *= a#Step2: multiplication原创 2017-09-25 00:24:07 · 216 阅读 · 0 评论 -
Lecture 7_2: Lists and mutability, dictionaries, pseudocode, introduction to efficiency
# example code, Lecture 7, Fall 2008import math#get baseinputOK = Falsewhile not inputOK: base = float(input('Enter base:')) #we get str in python 3x from input, we need to convert str t原创 2017-09-25 00:21:14 · 164 阅读 · 0 评论 -
Lecture 7_1: Lists and mutability, dictionaries, pseudocode, introduction to efficiency
# example code, Lecture 7, Fall 2008def showDicts(): EtoF = {'one': 'un', 'soccer': 'football', 'never': 'janaie'} print (EtoF['soccer']) input()# print (EtoF[0]) #Dictionary is原创 2017-09-25 00:17:34 · 142 阅读 · 0 评论 -
Lecture 6: Bisection methods, Newton/Raphson, introduction to lists
# example code, Lecture 6, Fall 2008s = 0for i in range(10): s += 0.1print (s)def squareRootBi(x,epsilon): '''Assumes x >= 0 and epsilon > 0 return y s.t. y*y is within epsilon of原创 2017-09-25 00:16:14 · 198 阅读 · 0 评论 -
Lecture 4: Decomposition and abstraction through functions; introduction to recursion
# example code, Lecture 4, Fall 2008def sqrt(x): ans = 0 if x >= 0: while ans*ans < x: ans = ans + 1 if ans*ans != x: print (x, 'if not a prefect square')原创 2017-09-25 00:14:37 · 256 阅读 · 0 评论 -
Lecture 3: Common code patterns: iterative programs
# example code, Lecture 3, Fall 2008x =16ans = 0while ans*ans < x: ans = ans + 1print (ans)x = 1515361ans = 0if x >= 0: while ans*ans < x: ans = ans + 1 print ('ans ='原创 2017-09-25 00:12:35 · 151 阅读 · 0 评论 -
Lecture 11: Testing and debugging
# Lecture 11 fall 2008def silly(): res = [] done = False while not done: while not done: elem = input('Enter element. Return when done. ') if elem == '':原创 2017-09-25 00:36:42 · 208 阅读 · 0 评论