I am trying to make a python class program that will accept a force and its direction as input and give the resultant with direction as output. The problem I have is that it wont store multiple x,y components inside the list I made supposedly to store them.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

I am trying to make a python class program that will accept a force and its direction as input and give the resultant with direction as output. The problem I have is that it wont store multiple x,y components inside the list I made supposedly to store them.

 

I hope you could help me imporve my code, thank you!

 

attached is a picture of the code I made

def solve_angle(self):
"""Solve for the angle of the resultant"""
xy = sum(self.x_components) / sum(self.y_components)
arctan = xy - xy ** 3 / 3 + xy ** 5 / 5 - xy ** 7 / 7 + xy
abs (arctan)
9 / 9
**
return arctan
int(input ('Enter number of forces: '))
= None
n_force
get_resultant
for n in range (0, n_force):
f = float(input('Enter magnitude of force: '))
direction = float(input('Enter the angle of force measured from the positive x-axis ccw: '))
while direction < 0:
direction = float(input("Please enter correct angle: "))
if direction > 360:
while direction > 360:
direction -= 360
diri = direction
dir2 = abs (direction
converted_d1 = (dir1 / 180)
converted_d2 = (dir2 / 180) * 3.14159262654
get_resultant = Resultant(f, direction, converted_d1, converted_d2)
get_resultant.solve_x_component()
get_resultant.solve_y_component()
90)
* 3.14159262654
resultant =
location =
get_resultant.solve_magnitude ()
get_resultant.solve_angle()
{location}')
print(f'{resultant}
Transcribed Image Text:def solve_angle(self): """Solve for the angle of the resultant""" xy = sum(self.x_components) / sum(self.y_components) arctan = xy - xy ** 3 / 3 + xy ** 5 / 5 - xy ** 7 / 7 + xy abs (arctan) 9 / 9 ** return arctan int(input ('Enter number of forces: ')) = None n_force get_resultant for n in range (0, n_force): f = float(input('Enter magnitude of force: ')) direction = float(input('Enter the angle of force measured from the positive x-axis ccw: ')) while direction < 0: direction = float(input("Please enter correct angle: ")) if direction > 360: while direction > 360: direction -= 360 diri = direction dir2 = abs (direction converted_d1 = (dir1 / 180) converted_d2 = (dir2 / 180) * 3.14159262654 get_resultant = Resultant(f, direction, converted_d1, converted_d2) get_resultant.solve_x_component() get_resultant.solve_y_component() 90) * 3.14159262654 resultant = location = get_resultant.solve_magnitude () get_resultant.solve_angle() {location}') print(f'{resultant}
class Resultant:
"""An attempt to compute for the approximate resultant and the direction of the given forces"""
init_(self, force, angle, angle1, angle2):
"""Initialize the attributes"""
self.force = force
self.angle = angle
self.angle1 = angle1
self.angle2 = angle2
self.sine = (self.angle1 - self.angle1 ** 3 / 6 + self.angle1 ** 5 / 120
def
self.angle1 ** 7 / 5040 + self.angle1 ** 9 / 362880)
(self.angle2
self.angle2 ** 7 / 5040) *
self.cosine =
self.angle2 ** 3 / 6 + self.angle2 ** 5 / 120 -
-
-1
if self.angle < 90:
self.cosine *= -1
self.x_components = []
self.y_components
[]
def solve_x_component(self):
"""Solve for the x-component of the force""'
X = self.force * self.cosine
self.x_components.append (x)
def solve_y_component(self):
"""Solve for the y-component of the force"""
y = self.force * self.sine
self.y_components.append (y)
def solve_magnitude(self):
"""Solve the magnitude of the resultant"""
magnitude = (sum(self.x_components) ** 2 + sum(self.y_components) ** 2) ** 0.5
return magnitude
Transcribed Image Text:class Resultant: """An attempt to compute for the approximate resultant and the direction of the given forces""" init_(self, force, angle, angle1, angle2): """Initialize the attributes""" self.force = force self.angle = angle self.angle1 = angle1 self.angle2 = angle2 self.sine = (self.angle1 - self.angle1 ** 3 / 6 + self.angle1 ** 5 / 120 def self.angle1 ** 7 / 5040 + self.angle1 ** 9 / 362880) (self.angle2 self.angle2 ** 7 / 5040) * self.cosine = self.angle2 ** 3 / 6 + self.angle2 ** 5 / 120 - - -1 if self.angle < 90: self.cosine *= -1 self.x_components = [] self.y_components [] def solve_x_component(self): """Solve for the x-component of the force""' X = self.force * self.cosine self.x_components.append (x) def solve_y_component(self): """Solve for the y-component of the force""" y = self.force * self.sine self.y_components.append (y) def solve_magnitude(self): """Solve the magnitude of the resultant""" magnitude = (sum(self.x_components) ** 2 + sum(self.y_components) ** 2) ** 0.5 return magnitude
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY