0

when I print, it says I cannot concatenate float and str. how do I fix this?

shape = input("what shape woul dyou like to choose: circle? triangle? rectangle? or a pentagon?") pie = float(3.141592)

if shape == "circle":

radius = float(input("what is the radius of the circle?"))

area = pie * (radius * radius)

perimeter = radius * pie * 2

print("the area of this circle is " + area)

print(" the  circumference of this circle is: " + perimeter)

elif shape == "triangle":

side_1 = float(input("input the value of one of the sides"))

side_2 = float(input("input the value of one of the sides"))

base = float(input("what is the base? "))

tri_perimeter = side_1 + side_2 

print("the perimeter of this triangle is " + tri_perimeter)

height = float(input("what is the height? "))

tri_area = (base * height)/2

print("the area of the triangle is " + tri_area)

elif shape == "rectangle":

base = float(input("what is the base? "))

height = float(input("what is the height? "))

rec_area = base * height

rec_perimeter = (base * 2) + (height * 2)

print("the area of the rectangle is " + rec_area)

print("the perimeter is " + rec_perimeter)

else: print("error!")

The part im actually struggling with, is when I want to print something (9area or perimeter). It says that I cannot concatenate str and float. How do I fix?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245

1 Answers1

1

You have to case it to a string before concatenate