Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 1 6 Challenge 210305 try 2
- # 2. Create a *function* that asks the user for the height and base of a triangle,
- # and then calculates and prints out its area.
- # (Note: The formula for the area of a triangle is base*height/2)
- def tarea():
- base = float(input(" input triangle Base dimension : "))
- print("You entered : ", base)
- height = float(input("input triangle Height dimension : "))
- print("You entered : ", height)
- area = (base * height)/2
- print("Triangle area is: ", area)
- return base, height, area
- # tarea() # Runs the function as requested
- b, h, a = tarea() # Extra. Runs the function and 'collects' the returned values.
- print()
- print("Using the 'return'ed variables outside of the def. :")
- print("Base = ", b)
- print("Height =", h)
- print("Area =", a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement