Advertisement
TonyMo

1_7_TriAreaDefRet2.py

Mar 20th, 2021
741
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. # Python 102 1 7 Challenge, 1_7_TriAreaDefRet2.py
  2. # Was 1_7_TriAreaDefRet1.py  https://pastebin.com/EDhh2FjN
  3. ''' Create a _function_ that accepts the dimensions of a triangle and _returns_ its area.
  4. Note: The formula for the area of a triangle is base*height/2 '''
  5.  
  6. '''
  7. Hi @TonyMoody. The function should take the base and height of the triangle as parameters, rather than asking for user input during the function '''
  8.  
  9. def tarea(base, height):
  10.     area = (base * height)/2
  11.     # print("Triangle area is: ", area) OK within def.
  12.     return area
  13.  
  14. # Test the function tarea()
  15. # b = 20  # also works OK
  16. # h = 30  # also works OK
  17. b = float(input("base ? :"))
  18. h = float(input("height ? :"))
  19. a = tarea(b, h) # this 'a' == 'area' in the def tarea()
  20. print("Area =", a)
  21.  
  22. '''
  23. >>>
  24. Area = 300.0
  25. >>>
  26. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement