[&]
3.144.102.138
workshop: #lesson-4.html
AD
mod3
py
app-3-1.py
app-3-2.py
# Chapter: 3.1 [15] # Subject: arrays # Time: 5 minutes # Go! from array import array a1 = [5,10,15] a2 = array('i',[5,10,15]); a3 = array('u',['A','B','C']); a4 = [13,'G',True] # Errors: #a3[0] = 'b52'; #print(a1[5]) # Display: print('Display:') print(a2[0]) print(a4[0]) a1.append('abc') print(a1[3]) a1[1] = 'cba' print(a1[1]) # Length: print('\r\nLength:') print('A1='+str(len(a1))) print('A2='+str(len(a2))) print('A3='+str(len(a3))) print('A4='+str(len(a4)))
# Chapter: 3.2 [16] # Subject: Arrays # Time: 3 minutes # Go! from array import array motd = "Niech moc będzie z Tobą" print(motd[0]); print(motd[6]); print(motd[10]); print(motd[17]); print(motd[19]);
# Chapter: 3.3 [17] # Subject: loops # Time: 2 minutes # Go! sum = 0 number = 1 while ( number < 13) : # powtarzające się działanie sum += number print(str(number)+") "+str(sum)) number+=1 tab = [5,10,15,1] # for x in [5,10,15]: for x in range(0,len(tab)): print("Poz: "+str(x)+" wartość: "+str(tab[x])) for x in range(len(tab)-1,-1,-1): print("Poz: "+str(x)+" wartość: "+str(tab[x])) print(tab)
# Chapter: 3.4 [18] # Subject: multidim-array # Time: 5 minutes # Go! from array import array aaa = [ [1,2,3,4,5], [6,7,8,9,10], [11,12,13,14,15], [16,17,18,19,20], [21,22,23,24,25] ] print(aaa)
# Chapter: 3.5 [19] # Subject: multidim-array # Time: 10 minutes # Go! from array import array aaa = [ [1,2,3,4,5], [6,7,8,9,10], [11,12,13,14,15], [16,17,18,19,20], [21,22,23,24,25] ] print('MDA:') print(aaa) print('Loop:') for i in range(0,len(aaa)): print(aaa[i]) print('2x Loop #1:') for i in range(0,len(aaa)): for j in range(0,len(aaa[i])): print(aaa[i][j]) print('2x Loop #2:') out = "" for i in range(0,len(aaa)): for j in range(0,len(aaa[i])): out+= str(aaa[i][j])+";" if j==len(aaa[i])-1: out+='\r\n' print(out)
# Chapter: 3.6 [20] # Subject: asoc-arrays (dict) # Time: 5 minutes # Go! marvel = { "name":"Deadpool", "volume": 1, "duration": 107, "released": 2016 } print(marvel) print(marvel["name"]) print(len(marvel)) dc = dict(); dc["name"] = "Batman vs. Superman" dc["volume"] = 2 dc["pages"] = 32 dc["price"] = 3.99 print(dc) print(dc["name"]) print(len(dc))
# Chapter: 3.7 [21] # Subject: dict iterate # Time: 12 minutes # Go! marvel = { "name":"Deadpool", "volume": 1, "duration": 107, "released": 2016 } print('Marvel k=>v #1:') for key in marvel: print(key+"="+str(marvel[key])) print('\r\nMarvel k=>v #2:') print(marvel.items()) print('\r\nMarvel k=>v #3:') for key,val in marvel.items(): print(key+"="+str(val)) dc = dict(); dc["name"] = "Batman vs. Superman" dc["volume"] = 2 dc["pages"] = 32 dc["price"] = 3.99 print('\r\nDC keys/values:') print(dc.keys()) print(dc.values()) print('\r\nDC keys()/values():') for key in dc.keys(): print('K: '+key) for val in dc.values(): print('V: '+str(val))