徐士然

@xsr0217

徐士然 暂无简介

所有 个人的 我参与的
Forks 暂停/关闭的

    徐士然/作业2

    a => 1 b => 2 c => 3 d => 4 e => 5 f => 6 g => 7 >>> for key in sorted(D): ... print(key, '=>', D[key]) 第三题 L = [1, 2, 4, 8, 16, 32, 64] X = 5 i = 0 while i < len(L): if 2 ** X == L[i]: print('at index', i) break i += 1 else: print(X, 'not found') L = [1, 2, 4, 8, 16, 32, 64] X = 5 for p in L: if (2 ** X) == p: print((2 ** X), 'was found at', L.index(p)) break else: print(X, 'not found') L = [1, 2, 4, 8, 16, 32, 64] X = 5 if (2

    徐士然/作业

    第一题 >>> S = 'spam' >>> for c in S: ... print(ord(c)) ... 115 112 97 109 >>> x = 0 >>> for c in S: x += ord(c) ... >>> x 433 >>> x = [] >>> for c in S: x.append(ord(c)) ... >>> x [115, 112, 97, 109] >>> list(map(ord, S)) [115, 112, 97, 109] 第二题 >>> D = {'a':1, 'b':2, 'c':3, 'd':4, 'e':5, 'f':6, 'g':7} >>> D {'f': 6, 'c': 3, 'a': 1, 'g': 7, 'e': 5, 'd': 4, 'b': 2} >>> >>> keys = list(D.keys()) >>> keys.sort() >>> for key in keys: ... print(key, '=>', D[key]) ..

搜索帮助