Please convert the following python program to LINE BY LINE python pseudocode.
Please convert LINE BY LINE (typed)
class vector:
def __init__(self,x,y):
self.x = x # Assigning x to vector's x
self.y = y # Assigning y to vector's y
def __str__(self):
return '('+str(self.x)+","+str(self.y)+')' # This returns the value of vector in bracket format
def __add__(self,other):
x = self.x+other.x # values of x of vector1 and vector2 are added forming new x value
y = self.y+other.y # same is done with value of y, self.x refer to value of vector1 and other.x refer x of vector2
res = vector(x,y) # Both values are made as vector
return res # Returning the resultant vector
def __sub__(self,other):
res = self+other*(-1) # As described, subtraction is prformed V*W(-1)
return res
def __mul__(self,other):
if type(other) == int: # If the vector2 is a integer value then each x,y is multiplied by n
res = vector(self.x * other,self.y * other) # result is converted to vector
else:
res = self.x * other.x + self.y * other.y #If the vector2 is vector type then dot product will be done like this
return res
def magnitude(self):
res = pow(self.x*self.x+self.y*self.y,0.5) # Calculating magnitude as per formula
return res
# Below is the code for testing of class
V = vector(1,2) # Assigning vector 1
W = vector(2,3) # Assigning vector 2
S = 5 # Assigning Scalar
# Performing the respective operations
print("V =",V)
print("W =",W)
print("S =",S)
print("V+W =",V+W)
print("V-W =",V-W)
print("V*W =",V*W)
print("V*S =",V*S)
print("Magnitude of V =",V.magnitude())Pseudocode
Vector CLASS
INITIALIZE Vector(x,y)
Vector.x = x
Vector.y = y
DEFINE Str()
RETURN "(" + Vector.x + "," +
Vector.y + ")"
DEFINE Add(Vector Other)
TempX = Vector.x + Other.x
TempY = Vector.y + Other.y
Result = Vector(TempX, TempY)
RETURN Result
DEFINE Sub(Vector Other)
Result = Vector + (-1)*Other
RETURN Result
DEFINE Mult(Vector Other)
IF Typeof(Other) is int
then Result =
Vector(Vector.x * Other.x, Vcetor.y * Other.y)
ELSE
Result =
Vector.x * Other.x + Vcetor.y * Other.y
RETURN Result
DEFINE Magnitude()
Result = SQR_ROOT(Vector.x *
Vector.x + Vector.y * Vector.y)
RETURN Result
V is Vector(1,2)
W is Vector(2,3)
S is 5
PRINT("V = " and W)
PRINT("W = " and W)
PRINT("S = " and S)
PRINT("V + W = " and V + W)
PRINT("V * W = " and V * W)
PRINT("V * S = " and V * W)
PRINT("Magnitude of V = " and V.Magnitude())
Please convert the following python program to LINE BY LINE python pseudocode. Please convert LINE BY...
Page 3 of 7 (Python) For each substring in the input string t that matches the regular expression r, the method call re. aub (r, o, t) substitutes the matching substring with the string a. Wwhat is the output? import re print (re.aub (r"l+\d+ " , "$, "be+345jk3726-45+9xyz")) a. "be$jk3726-455xyz" c. "bejkxyz" 9. b. "be$jks-$$xyz" d. $$$" A object a- A (2) 10. (Python) What is the output? # Source code file: A.py class A init (self, the x): self.x-...
[Problem 5] List all that the following Python class is missing in order to function. [10 Points] import math class TwoCoordinatePoints (object): #This class represents a point A = (x, y) with integer values for x and y. -_init__(x, y): self.x = x self.y = y def -_str__(self): "(%, %)" % (self.x, self.y) def distance (self, P): #computes the distance between two points (instances) of this class return math.sqrt((self.x-P.x)**2+(self.y-P.y)**2)
## python oop creating a large number of instances ## im trying to create a large number of instances for a class. could you show me a way to make it work import math import random class soldiers: def __init__(self,x,y): self.x = x self.y = y def get_target(self,x,y,number_red_soldiers,number_blue_soldiers): pass # self.target = def aiming_angle(self,x,y,target,enemy_x,enemy_y): dy = self.y-enemy_y[target] dx = self.x-enemy_x[target] angle =math.atan(dy/dx) a = 0 number_blue_soldiers= 10 number_red_soldiers = 10 for i in range(number_blue_soldiers): blue_x = random.randint(0,100,10) blue_y = random.randint(0,100,10)...
Python UML .Can anyone helpe to understand the pthon UML, I appreicated it . Giving the python code as follows: class C(object): pass class D(object): pass class A(object): def _ _init_ _(self,x,y); self.x=x; self.y=y; def hello (self,str); prnt(str +str(c)) class B(A); def _ _init_ _(self); #this is "aggregation" not composition" self.c= C self.d= D if _ _name_ _ =="_ _main_ _"; a=A(10,20) # a=A(20,30) # (a)Draw an UML Class Diagram of A ,and an UML Class Diagram of B (b)Draw...
#python oop referencing attributes in objects # problem is the angle function in my class. import random class people(): def __init__(self,x,y,size_of_other_team): self.x=x self.y=y self.target = random.randint(0,size_of_other_team) # choose a random guy from other team def angle(self, other_teams_x, other_teams_y): # get angle between this guy and his target dx = other_teams_x[self.target]-self.x dy = other_teams_y[self.target]-self.y theta = math.atan(dy/dx) return(theta) def move(self): self.x+=1 red_guys = 10 blue_guys = 10 red_x=[] red_y=[] red=[] # objects list for i in range(red_guys): red_x.append(random.randint(0,100)) red_y.append(random.randint(0,100)) red_person =...
Here is a Python program. import turtle class Box: def __init__(self, x, y, width, height): self.x = x self.y = y self.width = width self.height = height def show(self): turtle.up() turtle.goto(x, y) turtle.down() for _ in range(2): turtle.forward(width) turtle.right(90) turtle.forward(height) turtle.right(90) bigbox = Box(-100, -150, 200, 300) bigbox.show() turtle.done() If you run the above program, it will produce an error. What is the keyword that has...
Need Help! in English Can not get program to run plz include detailed steps as comments of what i did not do what I have done so far class Point: def __init__(self): self._x = 0 self._y = 0 def getX(self): return self._x def setX(self, val): self._x = val def getY(self): return self._y def setY(self, val): self._y = val def __init__(self, initX = 0, initY = 0): self._x = initX self._y = initY def __str__(self): return '<'+str(self._x)+', '+str(self._y)+ '>' def scale(self, factor):...
11p
Python Language
Read the following code for oofraction. import oofraction class OOFraction: def main(): fl = oofraction.o0Fraction( 2, 5) f2 = oofraction.o0Fraction ( 1, 3) f3 = f1 + f2 print (str(3)) main() def __init__(self, Num, Den): self.mNum = Num self.mDen = Den return def_add_(self,other): num = self.mNumother.mDen + other.mNum*self.mDen den = self.mDen*other.mDen f = OOFraction(num,den) return f 1. Write the output below. def_str_(self): s = str( self.mNum )+"/" + str( self.mDen) returns 2. Write a class called wholeNum...
Please code in Python Revise the AbstractBag class so that it behaves as a subclass of AbstractCollection provided in the file abstractcollection.py. Abstractcollection.py code: class AbstractCollection(object): """An abstract collection implementation.""" # Constructor def __init__(self, sourceCollection = None): """Sets the initial state of self, which includes the contents of sourceCollection, if it's present.""" self.size = 0 if sourceCollection: for item in sourceCollection: self.add(item) # Accessor methods def isEmpty(self): """Returns True if len(self) == 0, or False otherwise.""" return len(self) == 0...
Python 3+ Adjust the following code so the two errors below are non-present: 1. __init__() : Since Pizza object don't have it's own set() datastructure, the toppings in the pizza object are manimupated from out of the object. (-1.0) 2. __eq__() : How about "self.toppings == other.toppings" rather than "self.toppings - other.toppin == set())". Code: ## Program 1 ## --------------------------------- class Pizza: def __init__(self, s='M', top=set()): self.setSize(s) self.toppings = top def setSize(self, s): self.size = s def getSize(self): return self.size...