Python Forum
error working with classes. what am i doing wrong?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error working with classes. what am i doing wrong?
#1
Hi, we have been provided with this section of code:


class beam(object):
    '''This class is models the deflection of a simply supported beam under
    multiple point loads, following Euler-Bernoulli theory and the principle of
    superposition
    '''

    def __init__(self, E, I, L):
        '''The class costructor
        '''
        self.E = E  # Young's modulus of the beam in N/m^2
        self.I = I  # Second moment of area of the beam in m^4
        self.L = L  # Length of the beam in m
        self.Loads = [(0.0, 0.0)]  # the list of loads applied to the beam

    def setLoads(self, Loads):
        '''This function allows multiple point loads to be applied to the beam
        using a list of tuples of the form (load, position)
        '''
        self.Loads = Loads
we then have to create a function within the class, called

def beamDeflection(self, Load, x):
I have entered the following code:

def beamDeflection(self, Load, x):
        P1, a = Load
        b = (self.L - a)
        if x>a:
            return ((p1*b)/6*L*E*I)*((L/b)*(x-a)**3 -x**3 +((L**2 -b**2)*x))
        else:
            return ((p1*b*x)/(6*L*E*I))*(L**2 - x**2 - b**2)
to test, we are given the following inputs:

z = beam(8.0E9, 1.333E-4, 5.0)
print(z.beamDeflection((1000,1.9),2.5)
this should provide an output of
0.00224790572643


instead I get an error of

SyntaxError: unexpected EOF while parsing

what am I doing wrong??

thanks

(full code below)


class beam(object):
    '''This class is models the deflection of a simply supported beam under
    multiple point loads, following Euler-Bernoulli theory and the principle of
    superposition
    '''

    def __init__(self, E, I, L):
        '''The class costructor
        '''
        self.E = E  # Young's modulus of the beam in N/m^2
        self.I = I  # Second moment of area of the beam in m^4
        self.L = L  # Length of the beam in m
        self.Loads = [(0.0, 0.0)]  # the list of loads applied to the beam

    def setLoads(self, Loads):
        '''This function allows multiple point loads to be applied to the beam
        using a list of tuples of the form (load, position)
        '''
        self.Loads = Loads

    def beamDeflection(self, Load, x):
        P1, a = Load
        b = (self.L - a)
        if x>a:
            return ((p1*b)/6*L*E*I)*((L/b)*(x-a)**3 -x**3 +((L**2 -b**2)*x))
        else:
            return ((p1*b*x)/(6*L*E*I))*(L**2 - x**2 - b**2)

z = beam(8.0E9, 1.333E-4, 5.0)
print(z.beamDeflection((1000,1.9),2.5)
Reply
#2
You are missing a close parenthesis on your final print statement.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

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