Advertisement
elena_gancedo

Exercice1_102

Jul 30th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. def calculation(operation):
  2.     if operation == "area1":
  3.        input1 = input("Base > ")
  4.        input2 = input("Heigh > ")
  5.        number1 = float(input1)
  6.        number2 = float(input2)
  7.        result = (number1 * number2)/2
  8.        output = str(result)
  9.        print ("The result of 'area1' is  " + str(result) + " m^2")
  10.     else:
  11.        input1 = input("Side 'a' > ")
  12.        input2 = input("Side 'b' > ")
  13.        input3 = input("Side 'c' > ")
  14.        number1 = float(input1)
  15.        number2 = float(input2)
  16.        number3 = float(input3)
  17.        result = (number1 + number2 + number3)/2
  18.        output = str(result)
  19.        print("The result of 'area2' is " + str(result) + " m^2")
  20.     return
  21. # Area1: Calculates the area using the base and height  
  22. # Area2: Calculates the area using triangulation (based on the length of the three sides)
  23. print("Let's do triangle's area")  
  24. # loop  
  25. finished = False
  26. while finished == False:
  27.     operation = input("What calculation would you like to do 'area1'> (base*heigh/2) or 'area2'> (side a + side b + side c /2)?: ")
  28.     if operation in  ["area1","area2"]:
  29.         calculation(operation)
  30.     else:
  31.         print("I'm sorry, I don't understand " + operation)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement