pyrebot

Better not to ignore the past but learn from it instead. Otherwise, history has a way of repeating itself.

博客园 首页 新随笔 联系 订阅 管理

2013年11月11日 #

摘要: python排序算法1、冒泡排序: 1 import math 2 def BubbleSort(list): 3 lengthOfList = len(list) 4 for i in range(0,lengthOfList-1): 5 for j in xrange(i+1,lengthOfList): 6 if list[i]>list[j]: 7 temp = list[i] 8 list[i] = list[j] 9 list[j]... 阅读全文
posted @ 2013-11-11 18:03 pyrebot 阅读(155) 评论(0) 推荐(0) 编辑

摘要: #2、已知a1=1,a2=2,an=a(n-1)+a(n-2)(n>=3),求数列{a1,a2,a3....an}的总和 1 import math 2 arr = [0]*100 3 num = 0 4 for i in range(0,100): 5 if i>=3: 6 arr[i]=arr[i-1] + arr[i-2] 7 num += arr[i] 8 else: 9 arr[i] = i + 110 num += arr[i]11 print num 阅读全文
posted @ 2013-11-11 15:05 pyrebot 阅读(212) 评论(0) 推荐(0) 编辑