这是一门用python实现矩阵运算的课,第一次作业就感觉对python的提高很大,用到了各种数据类型。
## Task 1 minutes_in_week = 60*24*7 ## Task 2 remainder_without_mod = 2304811-2304811//47*47 ## Task 3 divisible_by_3 = (673+909)/3==0 ## Task 4 x = -9 y = 1/2 statement_val = 2**(y+1/2) if x+10<0 else 2**(y-1/2) ## Task 5 first_five_squares = { x*x for x in {1,2,3,4,5} } ## Task 6 first_five_pows_two = { 2**x for x in {0,1,2,3,4} } ## Task 7: enter in the two new sets X1 = { 1, 2, 3 } Y1 = { 4, 11, 17 } ## Task 8: enter in the two new sets X2 = { 1, 2, 0 } Y2 = { 4, 8, 16 } ## Task 9 base = 10 digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} three_digits_set = { base**2*x+base*y+z for x in digits for y in digits for z in digits } ## Task 10 S = {1, 2, 3, 4} T = {3, 4, 5, 6} S_intersect_T = { x for x in S if x in T } ## Task 11 L_average = sum([20, 10, 15, 75])/len([20, 10, 15, 75]) # average of: [20, 10, 15, 75] ## Task 12 LofL = [[.25, .75, .1], [-1, 0], [4, 4, 4, 4]] LofL_sum = sum({sum(LofL[x]) for x in range(0,len(LofL))}) # use form: sum([sum(...) ... ]) ## Task 13 cartesian_product = [[x,y] for x in {'A','B','C'} for y in {1,2,3} ] # use form: [ ... {'A','B','C'} ... {1,2,3} ... ] ## Task 14 S = {-4, -2, 1, 2, 5, 0} zero_sum_list = [ (x,y,z) for x in S for y in S for z in S if x+y+z==0 ] ## Task 15 exclude_zero_list = [ (x,y,z) for x in S for y in S for z in S if (x+y+z==0) and (x or y or z) ] ## Task 16 first_of_tuples_list = [ (x,y,z) for x in S for y in S for z in S if (x+y+z==0) and (x or y or z) ][0] ## Task 17 L1 = [1,1,2] # <-- want len(L1) != len(list(set(L1))) L2 = [2,1,3] # <-- same len(L2) == len(list(set(L2))) but L2 != list(set(L2)) ## Task 18 odd_num_list_range = { x for x in range(1,100,2)} ## Task 19 L = ['A','B','C','D','E'] range_and_zip = list(zip(list(range(5)),L)) ## Task 20 list_sum_zip = [x+y for (x,y) in zip([10,25,40],[1,15,20])] ## Task 21 dlist = [{'James':'Sean', 'director':'Terence'}, {'James':'Roger', 'director':'Lewis'}, {'James':'Pierce', 'director':'Roger'}] k = 'James' value_list = [d[k] for d in dlist] ## Task 22 dlist = [{'Bilbo':'Ian','Frodo':'Elijah'},{'Bilbo':'Martin','Thorin':'Richard'}] k = 'Bilbo' value_list_modified_1 = [d[k] if k in d else 'NOT PRESENT' for d in dlist] # <-- Use the same expression here k = 'Frodo' value_list_modified_2 = [d[k] if k in d else 'NOT PRESENT' for d in dlist] # <-- as you do here ## Task 23 square_dict = {x:x**2 for x in range(100)} ## Task 24 D = {'red','white','blue'} identity_dict = {x:x for x in D} ## Task 25 base = 10 digits = set(range(10)) representation_dict = { base**2*x+base*y+z:[x,y,z] for x in digits for y in digits for z in digits} ## Task 26 d = {0:1000.0, 1:1200.50, 2:990} names = ['Larry', 'Curly', 'Moe'] listdict2dict = { names[x]:y for (x,y) in d.items() } ## Task 27 def nextInts(L): return [ x+1 for x in L ] ## Task 28 def cubes(L): return [ x**3 for x in L ] ## Task 29 def dict2list(dct, keylist): return [ dct[x] for x in keylist ] ## Task 30 def list2dict(L, keylist): return { x:y for (x,y) in zip(keylist,L) }
在linux下提交按照说明即可,但在windows下面,就要费好大一番功夫了。
由于submit_python_lab.py里面默认待提交的py文件在当前目录下,必须把py文件和submit_python_lab.py文件拷贝到python3的安装文件夹下面。我用的是python3.3,因此要拷贝到的目录为:C:\Python33。论坛说双击submit_python_lab.py输入账号密码即可,为了方便我使用bat脚本文件运行:
C:\Python33\python C:\Python33\submit_python_lab.py