Advertisement
SimeonTs

SUPyF Functions - 05. Calculate Triangle Area

Jun 15th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. """
  2. Functions and Debugging
  3. Проверка: https://judge.softuni.bg/Contests/Compete/Index/922#4
  4.  
  5. 05. Calculate Triangle Area
  6.  
  7. Условие:
  8. Create a function that calculates and returns the area of a triangle by given base and height.
  9. Use a general formatting with 12 digits after the decimal point (e.g. {area:.12g})
  10.  
  11. Examples
  12. Input:
  13. 3
  14. 4
  15. Output:
  16. 6
  17.  
  18. Hints
  19. 1.  After reading the input
  20. 2.  Create a function that calculates the area.
  21. 3.  Invoke the function in the main and save the return value in a new variable.
  22. """
  23.  
  24.  
  25. def triangle_area(b, h):
  26.     area = b * h / 2
  27.     return f"{area:.12g}"
  28.  
  29.  
  30. # Тук използвам принта за взимане на данни от конзилата и едновременно да принтира резултата от функцията по-горе.
  31. # Друг вар. е да се вика с променлива, която да съдържа името на функцията с 2та инпута и после да принтираме тази
  32. # променлива, когато си решим :)
  33.  
  34. print(triangle_area(float(input()), float(input())))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement