Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #esercizio 1
- def changeX(pic,x):
- #param pic: Picture
- #param x: Int
- assert x>=0 and x <=getWidth(pic)
- assert getWidth(pic)==getHeight(pic)
- for c in range(0,getWidth(pic)):
- colC=getColor(getPixel(pic,x,c))
- colR=getColor(getPixel(pic,c,x))
- setColor(getPixel(pic,c,x),colC)
- setColor(getPixel(pic,x,c),colR)
- repaint(pic)
- #esercizio 2
- def changeXInt(mat,x):
- #param mat: List
- #param x: Int
- assert x>=0 and x<=len(mat)
- assert checkMat(mat)
- for c in range(0,len(mat)):
- app=mat[x][c]
- mat[x][c]=mat[c][x]
- mat[c][x]=app
- def checkMat(mat):
- #param mat:List
- #return: bool
- for i in range(0,len(mat)):
- if len(mat[i])!=len(mat):
- return False
- return True
- #esercizio 3
- def modifyPicture(pic,x,y,col):
- #param pic: Picture
- #param x:int
- #param y:int
- #param c:Color
- assert x<=getWidth(pic)-1 and y<=getHeight(pic)-1 and x>=0 and y>=0
- if getHeight(pic)-y<=getWidth(pic)-x:
- while y<getHeight(pic)-1:
- pix=getPixel(pic,x,y)
- setColor(pix,col )
- x=x+1
- y=y+1
- repaint(pic)
- else:
- while x< getWidth(pic)-1:
- pix=getPixel(pic,x,y)
- setColor(pix,col)
- x=x+1
- y=y+1
- repaint(pic)
- #esercizio 4
- def annulDiagonal(x,y,mat):
- #param x: int
- #param y: int
- #param mat: List
- i=0
- assert x>=0 and y>=0 and x<=len(mat[i]) and y<=len(mat) and len(mat)>0
- if len(mat)-y<=len(mat[i])-x:
- while y+i<len(mat):
- mat[x+i][y+i]=0
- i+=1
- else:
- while x+i<len(mat[i]):
- mat[x+i][y+i]=0
- i+=1
- #esercizio 5
- def value(lista):
- #param lista: List
- #return: int
- newString=""
- cont=0
- assert len(lista)>0
- for i in range(0,len(lista)):
- if not str(lista[i]) in newString:
- newString=newString+str(lista[i])
- cont+=1
- return cont
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement