80 likes | 366 Views
Python for Bioinformatics. Midterm Redo Solution. 1. Show the output from the following program fragments: (a) for i in range(5): print(i%3) #i%3 is the remainder after dividing i by 3 for d in [3,'.',1,4,1,5]: print( d,end ='')
E N D
Python for Bioinformatics Midterm Redo Solution
1. Show the output from the following program fragments: (a) for i in range(5): print(i%3) #i%3 is the remainder after dividing i by 3 for d in [3,'.',1,4,1,5]: print(d,end='') # end = '' means all on one line, no separator (c) for i in range(4): print(i*'x') # i*'x' means repeat x i times 0 1 2 3 4 3.1415 ******
1. Show the output from the following program fragments: (d) print(list('goodbye')) # list(astring) produces a list whose # elements are the characters of astring (f) D = {} D['uno'] = 'one' D['dos'] = 'two' D['tres'] = 'three' D['cuatro'] = 'four' for k in D:print(k,'->',D[k]) ['g','o','o','d','b','y','e'] D = {'uno':'one'} D = {'uno':'one','dos':'two'} D = {'uno':'one','dos':'two','tres':'three'} D = {'uno':'one','dos':'two','tres':'three','quatro':'four} uno -> one dos -> two tres > three quatro -> four