摘要: def demo(t): print([1]) print([1, 1]) line = [1, 1] for i in range(2, t): r = [] for j in range(0, len(line) - 1): r.append(line[j] + line[j + 1]) ... 阅读全文
posted @ 2018-02-27 20:16 守护窗明守护爱 阅读(432) 评论(0) 推荐(0) 编辑
摘要: def fib(n): a, b = 1, 1 while a < n: print(a, end=' ') a, b = b, a + b fib(100000) #输出结果 #1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 2865... 阅读全文
posted @ 2018-02-27 19:41 守护窗明守护爱 阅读(339) 评论(0) 推荐(0) 编辑
摘要: import math n = int(input('Input an integer:')) m = int(math.sqrt(n) + 1) for i in range(2, m): if n % i == 0: print('No') break else: print('Yes') #输 阅读全文
posted @ 2018-02-24 21:11 守护窗明守护爱 阅读(324) 评论(0) 推荐(0) 编辑
摘要: for i in range(100, 1000): ge = i % 10 shi = i // 10 % 10 bai = i // 100 if ge ** 3 + shi ** 3 + bai ** 3 == i: print(i, end=' ') #输出结果 #153 370 371 407 阅读全文
posted @ 2018-02-24 21:05 守护窗明守护爱 阅读(388) 评论(0) 推荐(0) 编辑
摘要: import time date = time.localtime() print(date) #time.struct_time(tm_year=2018, tm_mon=2, tm_mday=24, tm_hour=19, tm_min=42, tm_sec=57, tm_wday=5, tm_yday=55, tm_isdst=0) year = date[0] month = dat... 阅读全文
posted @ 2018-02-24 19:44 守护窗明守护爱 阅读(1326) 评论(0) 推荐(0) 编辑
摘要: 生成包含 1000 个随机字符的字符串,并统计每个字符出现的次数。 阅读全文
posted @ 2018-02-23 14:19 守护窗明守护爱 阅读(343) 评论(0) 推荐(0) 编辑
摘要: import math a = [p for p in range(2, 100) if 0 not in [p % d for d in range(2, int(math.sqrt(p)) + 1)]] print(a) #输出结果 #[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 7... 阅读全文
posted @ 2018-02-22 20:45 守护窗明守护爱 阅读(2239) 评论(0) 推荐(0) 编辑
摘要: 使用列表推导式实现二维矩阵转置 使用内置函数 zip() 秩代、map() 和 list() 映射实现二维矩阵转置 阅读全文
posted @ 2018-02-22 20:32 守护窗明守护爱 阅读(592) 评论(0) 推荐(0) 编辑
摘要: 在删除列表元素时,Python 会自动对列表内存进行收缩,并移动列表元素,以保证元素之间没有空隙。每当插入或删除一个元素之后,该元素位置后面所有元素的索引就都改变了。以下代码说明这个问题。 可见,由于 Python 的自动内存管理机制,通过这种方式并不能实现把 “1” 去除的效果。因此,我们下面试试 阅读全文
posted @ 2018-02-22 15:36 守护窗明守护爱 阅读(349) 评论(0) 推荐(0) 编辑
摘要: menu = { "北京": { "朝阳区": { "三环到四环之间": {}, "四环到五环之间": {}, "五环到六环之间": {}, "管庄": {}, "北苑": {}, ... 阅读全文
posted @ 2018-02-10 16:07 守护窗明守护爱 阅读(816) 评论(0) 推荐(1) 编辑