Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python exercise
#1
Hello,

I was trying to solve an exercise where I needed to calculate the area of the box where I should input the coordinates of the specific box (Box1 or Box2) and then calculate the area.
This is my code so far:

import numpy as np


def boxArea(boxCorners, area):
    x = np.array([boxCorners])
     
    if area == "Box1":
        x = np.array([boxCorners])
        A = ((x[1]-x[0])*(x[3]-x[2]))
        
    elif area == "Box2":
        
        A = ((x[1]-x[0])*(x[3]-x[2]))
        
        return A
The problem is that I constantly get this error message: "IndexError: index 1 is out of bounds for axis 0 with size 1". I really do not understand what is the problem in this code. Hope that someone can help me. Smile
Reply


Messages In This Thread
Python exercise - by janaraguz - Sep-22-2018, 08:30 PM
RE: Python exercise - by ichabod801 - Sep-22-2018, 08:37 PM
RE: Python exercise - by ichabod801 - Sep-22-2018, 08:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Exercise Vasanth0910 1 2,015 May-15-2020, 04:41 PM
Last Post: pyzyx3qwerty
  Python exercise HY2000 2 3,339 Nov-07-2019, 08:01 AM
Last Post: HY2000
  Simple exercise - how to write in python tomtom55 6 5,238 Sep-28-2017, 07:18 PM
Last Post: nilamo
  Python Exercise: Generate a two-dimensional array smbx33 4 11,195 Apr-22-2017, 11:51 PM
Last Post: smbx33

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020