Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import tkinter
- #Tyler Matsunami
- #finals review
- #Question 1
- def square(x):
- return x**2
- def mapIt(nlist):
- return list(map(square, nlist))
- #Question 2
- def findnumbers(inputStr, pattern):
- regex = re.compile(r'' + pattern)
- return list( filter( regex.findall, inputStr ))
- #Question 3
- #assuming tkinter object and canvas has already been declared AND assuming that
- #the points are objects with methods, getX() and getY()
- def drawTriangle (left, mid, right,canvas): #where left, mid and right are instances of a Point class with methods getX() and getY()
- canvas.create_line(left.getX(),left.getY(),mid.getX(),mid.getY())
- canvas.create_line(mid.getX(),mid.getY(), right.getX(),right.getY())
- canvas.create_line(right.getX(),right.getY(),left.getX(),left.getY())
- class Point():
- def __init__(self,x,y):
- self.x=x
- self.y=y
- def getX(self):
- return self.x
- def getY(self):
- return self.y
- #Question 1 Test
- testList = [1,2,3,4,5,6]
- squares = mapIt(testList)
- print(squares)
- #Question 2 test
- testStr = "Hello 132 my name is2 bob3132"
- print(findnumbers(testStr.lower(), "[^a-z, ]"))
- #Question 3 Test
- root = tkinter.Tk()
- canvas = tkinter.Canvas(root, width = 800, height = 600, bg = "white")
- leftPt = Point(30,40)
- midPt = Point(80,40)
- rightPt = Point(55,80)
- drawTriangle(leftPt, midPt, rightPt,canvas)
- canvas.pack()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement