#how to get an area of triangle printed instead of what is getting printed now

1 messages · Page 1 of 1 (latest)

karmic pollen
worn pewter
#

right now, you’re placing those values into a string which cannot be used for calculations. one way to do this would be to make a variable such as
area = base * height * 0.5 and then you can print “area of rec: “ + area

#

apologies for the lack of formatting, i’m on my phone

bleak siren
#

“area of rec: “ + area
Or with string interpolation

area = base * height * 0.5
print(f"area of triangle: {area}")

You could also calculate it directly in the brackets

print(f"area of triange = {base * height * 0.5}")

But the first version is generally preferred.

#

;compile

base = 4.5
height = 5.6

area = base * height * 0.5

print(f"area of triangle = {base} * {height} * 0.5 = {area}")
print(f"area of triangle = {base} * {height} * 0.5 = {base * height * 0.5}")
boreal sluiceBOT
#
Program Output
area of triangle = 4.5 * 5.6 * 0.5 = 12.6
area of triangle = 4.5 * 5.6 * 0.5 = 12.6