0

I am very new to Python and I have written my first code to calculate the area of shapes. Each time I run it on Jupyter, it says

Type Error.

where I got things wrong? (I am using Python 3).

# Calculator code for the area of the shape

print("1 rectangle")
print ("2 squared")
print ("3 circle")
shape = input (">> ")

if shape ==1:
   length = input ("What is the length of the rectangle?") 
   breadth = input ("What is the breadth of the rectangle?")
   area = length * breadth *2
   print ("the area of your rectangle", area)

elif shape == 2:
  length = input ("what is the length of one side of the squared")
  area = length *breadth
  print ("the area of your square is ", area)

else shape ==3:
  radius = input ("what is the radius of your circle")
  area = radius *radius*3.14
  print ("area of your circle is ", area)
skaul05
  • 2,154
  • 3
  • 16
  • 26
cdad
  • 25
  • 3

1 Answers1

0

You have some things wrong in your code:

  1. You have not provided any type to your input. Replace it with float for better calculation.
  2. You have written the wrong syntax of else. See the documentation
  3. You have calculated the area of square wrongly.

Try below code:

print("1 rectangle")
print("2 squared")
print("3 circle")
shape = input (">> ")

if shape == 1:
    length = float(input ("What is the length of the rectangle?"))
    breadth = float(input ("What is the breadth of the rectangle?"))
    area = length * breadth *2
    print ("the area of your rectangle", area)

elif shape == 2:
    length = float(input ("what is the length of one side of the squared"))
    area = length * length
    print ("the area of your square is ", area)

else:
    radius = float(input ("what is the radius of your circle"))
    area = radius *radius*3.14
    print ("area of your circle is ", area)

Hope this answers your question!!!

skaul05
  • 2,154
  • 3
  • 16
  • 26