Commit 3eb0794
Changed files (1)
projects
2
projects/2/prog4.py
@@ -5,3 +5,71 @@ Program author: mo khan
ID: 3431709
Program 4 - Functions
""")
+
+def menu():
+ print("""
+ CALCULATIONS MENU
+
+ 1) AREA (SQUARE)
+ 2) AREA (RECTANGLE)
+ 3) AREA (CIRCLE)
+ 4) PERIMETER (SQUARE)
+ 5) PERIMETER (RECTANGLE)
+ 6) PERIMETER (CIRCLE)
+ 7) EXIT
+ """)
+
+ return int(input("INPUT MENU CHOICE (1,2,3,4,5,6 OR 7)? "))
+
+def area_square():
+ print("YOU HAVE CHOSEN AREA (SQUARE)")
+ length = int(input("INPUT LENGTH? "))
+ print("AREA IS {}".format(length*length))
+
+def area_rectangle():
+ print("YOU HAVE CHOSEN AREA (RECTANGLE)")
+ width = int(input("INPUT WIDTH? "))
+ length = int(input("INPUT LENGTH? "))
+ print("AREA IS {}".format(length*width))
+
+def area_circle():
+ print("YOU HAVE CHOSEN AREA (CIRCLE)")
+ radius = int(input("INPUT RADIUS? "))
+ print("AREA IS {}".format(3.4* radius**2))
+
+def perimeter_square():
+ print("YOU HAVE CHOSEN PERIMETER (SQUARE)")
+ length = int(input("INPUT LENGTH? "))
+ print("PERIMETER IS {}".format(4*length))
+
+def perimeter_rectangle():
+ print("YOU HAVE CHOSEN PERIMETER (RECTANGLE)")
+ width = int(input("INPUT WIDTH? "))
+ length = int(input("INPUT LENGTH? "))
+ print("PERIMETER IS {}".format(2*length+2*width))
+
+def perimeter_circle():
+ print("YOU HAVE CHOSEN PERIMETER (CIRCLE)")
+ radius = int(input("INPUT RADIUS? "))
+ print("PERIMETER IS {}".format(2*3.14*radius))
+
+def main():
+ choice = 0
+ while choice != 7:
+ if choice == 1:
+ area_square()
+ elif choice == 2:
+ area_rectangle()
+ elif choice == 3:
+ area_circle()
+ elif choice == 4:
+ perimeter_square()
+ elif choice == 5:
+ perimeter_rectangle()
+ elif choice == 6:
+ perimeter_circle()
+ elif choice == 7:
+ exit(0)
+ choice = menu();
+
+main()