Friday, 4 March 2022

Python Program to find Area of Rectangle

 CODE

def main() : 

    print ("This program computes the area of Rectangle") 

    length = float (input ("Enter length: ") )

    width = float (input ("Enter width: ") ) 

    ans = length * width

    print ("Area of Rectangle: ", ans) 

main()

save above file as areaofrectangle.py

SCREENSHOT



Python Program to Find Area of Cylinder

 CODE

def main() : 

    print ("This program computes the area of Cylinder") 

    rd = float (input ("Enter Radius of Cylinder: ") )

    h = float (input ("Enter Height of Cylinder: ") ) 

    ans = 2 * 3.14 * rd * h + 2 * 3.14 * rd *rd

    print ("Area of Cyclinder: ", ans) 

main()

save file as areaofcylinder.py


SCREENSHOT



Python program to find Area of Circle

 CODE

def main() : 

    print ("This program computes the area of circle") 

    rd = float (input ("Enter Radius of Circle: ") ) 

    ans = 3.14 * rd *rd

    print ("Area of Circle: ", ans) 

main()

save above file as : areaofcircle.py

SCREENSHOT




Wednesday, 2 March 2022

Python Program To Draw a Line segment using Line Object

 SCREENSHOT



CODE

#Draw a line Segment using a Line object 


from graphics import *

def main():

    win = GraphWin('Draw Square',300,300)

    

    center = Point(100,100) 

    line=Line(Point(20,30),Point(180,165))

    line.draw(win)


main()

Python Program to Draw Square using Rectangle Object

 SCREENSHOT

CODE

#Draw a square using a Rectangle object 

from graphics import *

def main():

    win = GraphWin('Draw Square',300,300)

    center = Point(100,100) 

    rect = Rectangle(Point(30,30), Point(150,150))

    rect.setFill("yellow")

    rect.draw(win) 

main()



Python Program Put a Textual Label inside red circle

SCREENSHOT



CODE

 #Draw a red circle centered at point (100,100) with radius 50 and with text Red Circle

from graphics import *

def main():

    win = GraphWin('Draw Circle',300,300)

    

    center = Point(100,100) 

    circ = Circle(center, 50) 

    circ.setFill('red') 

    circ.draw(win)


    label = Text(center, "Red Circle") 

    label.draw(win)

main()


Python Program Draw a red circle centered at point (100,100) with radius 30

SCREENSHOT



CODE

 #Draw a red circle centered at point (100,100) with radius 30

from graphics import *

def main():

    win = GraphWin('Draw Circle',300,300)

    center = Point(100,100) 

    circ = Circle(center, 30) 

    circ.setFill('red') 

    circ.draw(win)

main()

An archery target consists of a central circle of yellow surrounded by concentric rings of red, blue, black and white

 CODE :

An archery target consists of a central circle of yellow surrounded by concentric rings of red, blue, black and white. Each ring has the same width, which is the same as the radius of the yellow circle. Write a program called target.py that draws this target.

o Use a list of colors and a for loop to draw the target

o Hint: objects drawn later will appear on top of objects drawn earlier

o The output of the program should look like this:

SCREENSHOT



SAVE this file as target.py

from graphics import *

def main():

    win = GraphWin('Archery Target',300,300)

    center = Point(150,150)


    w = Circle(center, 100)

    w.setFill('white')

    w.draw(win)


    bl = Circle(center, 80)

    bl.setFill('black')

    bl.draw(win)


    b = Circle(center, 60)

    b.setFill('blue')

    b.draw(win)


    r = Circle(center, 40)

    r.setFill('red')

    r.draw(win)


    y = Circle(center, 20)

    y.setFill('yellow')

    y.draw(win)


    win.getMouse() # pause for click in window

    win.close()


main()