Advertisement
TonyMo

triareadef2.py

Mar 5th, 2021
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. # 1 6 Challenge 210305 try 2
  2. #  2. Create a *function* that asks the user for the height and base of a triangle,
  3. #  and then calculates and prints out its area.
  4. # (Note: The formula for the area of a triangle is base*height/2)
  5.  
  6. def tarea():
  7.     base = float(input(" input triangle Base dimension : "))
  8.     print("You entered : ", base)
  9.     height = float(input("input triangle Height dimension : "))
  10.     print("You entered : ", height)
  11.     area = (base * height)/2
  12.     print("Triangle area is: ", area)
  13.     return base, height, area
  14.  
  15. # tarea() # Runs the function as requested
  16.  
  17. b, h, a = tarea() # Extra. Runs the function and 'collects' the returned values.
  18. print()
  19. print("Using the 'return'ed variables outside of the def. :")
  20. print("Base = ", b)
  21. print("Height =", h)
  22. print("Area =", a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement