• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Dec 14th, 2019 120 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #esercizio 1
2.
3. def changeX(pic,x):
4. #param pic: Picture
5. #param x: Int
6.   assert x>=0 and x <=getWidth(pic)
7.   assert getWidth(pic)==getHeight(pic)
8.   for c in range(0,getWidth(pic)):
9.     colC=getColor(getPixel(pic,x,c))
10.     colR=getColor(getPixel(pic,c,x))
11.     setColor(getPixel(pic,c,x),colC)
12.     setColor(getPixel(pic,x,c),colR)
13.
14.   repaint(pic)
15.
16.
17.
18. #esercizio 2
19.
20.
21. def changeXInt(mat,x):
22. #param mat: List
23. #param x: Int
24.   assert x>=0 and x<=len(mat)
25.   assert checkMat(mat)
26.   for c in range(0,len(mat)):
27.     app=mat[x][c]
28.     mat[x][c]=mat[c][x]
29.     mat[c][x]=app
30.
31.
32.
33.
34. def checkMat(mat):
35. #param mat:List
36. #return: bool
37.   for i in range(0,len(mat)):
38.     if len(mat[i])!=len(mat):
39.       return False
40.   return True
41.
42.
43.
44. #esercizio 3
45.
46. def modifyPicture(pic,x,y,col):
47. #param pic: Picture
48. #param x:int
49. #param y:int
50. #param c:Color
51.   assert x<=getWidth(pic)-1 and y<=getHeight(pic)-1 and x>=0 and y>=0
52.   if getHeight(pic)-y<=getWidth(pic)-x:
53.     while y<getHeight(pic)-1:
54.       pix=getPixel(pic,x,y)
55.       setColor(pix,col )
56.       x=x+1
57.       y=y+1
58.       repaint(pic)
59.   else:
60.     while x< getWidth(pic)-1:
61.       pix=getPixel(pic,x,y)
62.       setColor(pix,col)
63.       x=x+1
64.       y=y+1
65.       repaint(pic)
66.
67.
68.
69. #esercizio 4
70.
71. def annulDiagonal(x,y,mat):
72. #param x: int
73. #param y: int
74. #param mat: List
75.   i=0
76.   assert x>=0 and y>=0 and x<=len(mat[i]) and y<=len(mat) and len(mat)>0
77.   if len(mat)-y<=len(mat[i])-x:
78.     while y+i<len(mat):
79.       mat[x+i][y+i]=0
80.       i+=1
81.   else:
82.     while x+i<len(mat[i]):
83.       mat[x+i][y+i]=0
84.       i+=1
85.
86.
87. #esercizio 5
88.
89.
90. def value(lista):
91. #param lista: List
92. #return: int
93.   newString=""
94.   cont=0
95.   assert len(lista)>0
96.   for i in range(0,len(lista)):
97.     if not str(lista[i]) in newString:
98.       newString=newString+str(lista[i])
99.       cont+=1
100.   return cont
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?