Week-6 Python Lab Programs
Week-6 Python Lab Programs
world = World()
draw_rectangle(a_canvas,box)
world.mainloop()
1. b. Add an attribute named color to your Rectangle objects and modify draw_rectangle
so that ituses the color attribute as the fill color.
world = World()
draw_rectangle(a_canvas,box)
world.mainloop()
1. c. Write a function called draw_point that takes a Canvas and a Point as arguments and
draws arepresentation of the Point on the Canvas.
world = World()
draw_point(a_canvas,p)
world.mainloop()
1. d. Define a new class called Circle with appropriate attributes and instantiate a few Circle
objects.Write a function called draw_circle that draws circles on the canvas.
class Point(object):
"represents a point in 2-D space"
p = Point()
p.x = 60
p.y = 15
class Circle(object):
"""Represents a circle.
attributes: center point, radius"""
c = Circle()
c.radius = 50
c.center = Point()
c.center.x = 20
c.center.y = 20
def draw_circle(canvas, circle):
drawn_canvas = world.ca(canvas.width, canvas.height)
drawn_canvas.circle([circle.center.x, circle.center.y], circle.radius)
world = World()
draw_circle(a_canvas,c)
world.mainloop()
2. Write a Python program to demonstrate the usage of Method Resolution Order (MRO) in
multiplelevels of Inheritances.
# 1) Begins with 0 or 91
# 2) Then contains 6,7 or 8 or 9.
# 3) Then contains 9 digits
Pattern = re.compile("(0|91)?[6-9][0-9]{9}")
return Pattern.match(number)
#main method
if __name__ == "__main__":