MIT_6001
文章平均质量分 79
sunner008
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Lecture 2: Operators and operands; statements; branching, conditionals, and iteration
# sample code for use in Lecture 2, Fall 2008 x = 3 x=x*x n = input('Enter a number:') print (n) x = 15 if (x/2)*2 == x: print ('even') else: print ('odd') z = 'b' if 'x'<z: print ('Hello')原创 2017-09-25 00:06:04 · 236 阅读 · 0 评论 -
Lecture 3: Common code patterns: iterative programs
# example code, Lecture 3, Fall 2008 x =16 ans = 0 while ans*ans < x: ans = ans + 1 print (ans) x = 1515361 ans = 0 if x >= 0: while ans*ans < x: ans = ans + 1 print ('ans ='原创 2017-09-25 00:12:35 · 209 阅读 · 0 评论 -
Lecture 4: Decomposition and abstraction through functions; introduction to recursion
# example code, Lecture 4, Fall 2008 def 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 · 327 阅读 · 0 评论 -
Lecture 6: Bisection methods, Newton/Raphson, introduction to lists
# example code, Lecture 6, Fall 2008 s = 0 for i in range(10): s += 0.1 print (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 · 277 阅读 · 0 评论 -
Lecture 7_1: Lists and mutability, dictionaries, pseudocode, introduction to efficiency
# example code, Lecture 7, Fall 2008 def showDicts(): EtoF = {'one': 'un', 'soccer': 'football', 'never': 'janaie'} print (EtoF['soccer']) input() # print (EtoF[0]) #Dictionary is原创 2017-09-25 00:17:34 · 199 阅读 · 0 评论 -
Lecture 7_2: Lists and mutability, dictionaries, pseudocode, introduction to efficiency
# example code, Lecture 7, Fall 2008 import math #get base inputOK = False while 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 · 235 阅读 · 0 评论 -
Lecture 8: Complexity; log, linear, quadratic, exponential algorithms
# code file for lecture 8, 2008 fall #interative exponent def 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 · 323 阅读 · 0 评论 -
Lecture 9: Binary search, bubble and selection sorts
# Lecture 9 fall 2008 def 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 · 215 阅读 · 0 评论 -
Lecture 10: Divide and conquer methods, merge sort, exceptions
# Lecture 10 fall 2008 def 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 · 316 阅读 · 0 评论 -
Lecture 11: Testing and debugging
# Lecture 11 fall 2008 def 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 · 300 阅读 · 0 评论
分享