Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- import tkinter.simpledialog
- import tkinter.messagebox
- root = Tk()
- w = Label(root, text="Measurements")
- w.pack()
- #use me as an example of how to do the rest.
- #area = lw
- def rectanglearea(length, width):
- area = length * width
- return area
- # 0 - make sure you look at the example above.
- #volume = lwh
- def prismvolume(length, width, height):
- return
- # 1
- #perimeter = side1 + side2 + side3
- def triangleperimeter(side1, side2, side3):
- return
- # 2 - it's one half base times height, so multiply and divide by two.
- #area = bh/2
- def trianglearea(base, height):
- return
- # 3 - yes, you need to use the paretheses.
- #perimeter = 2(l + w)
- def rectangleperimeter(length, width):
- return
- #EXTRA CREDIT. The Surface Area of a rectangular prism is the perimeter of the base
- #multiplied by the height(SA = ph). Write a function to calulate the surface area
- #of a rectangular prism with sides 5, 7 and 2. Write it as efficiently as
- #possible (don't rewrite code that you don't have to)
- areaR = rectanglearea(5, 7)
- tkinter.messagebox.showinfo("rectangle area", "Area of a rectangle with sides 5 and 7 is " + str(areaR))
- volumeP = prismvolume(5, 7, 2)
- tkinter.messagebox.showinfo("prism volume", "Volume of a rectagular prism with sides 5, 7 and 2 is " + str(volumeP))
- perimeterT = triangleperimeter(10, 7, 8)
- tkinter.messagebox.showinfo("triangle perimeter", "Perimeter of a triangle with sides 10, 7 and 8 is " + str(perimeterT))
- areaT = trianglearea(6, 8)
- tkinter.messagebox.showinfo("triangle area", "Area of a triangle with base 6 and height 8 is " + str(areaT))
- perimeterR = rectangleperimeter(5, 8)
- tkinter.messagebox.showinfo("rectangle perimeter", "Perimeter of a rectangle with sides 5 and 8 is " + str(perimeterR))
- #
- # If your program works, you should get the following answers:
- #
- # Area of a rectangle with sides 5 and 7 is 35
- # Volume of a rectagular prism with sides 5, 7 and 2 is 70
- # Perimeter of a triangle with sides 10, 7 and 8 is 25
- # Area of a triangle with base 6 and height 8 is 24
- # Perimeter of a rectangle with sides 5 and 8 is 26
- #
- # Extra Credit:
- # Surface Area of a rectangular prism with sides 5, 7 and 2 is 48
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement