Tell us what’s happening:
Dear Team,
I need your advice. And please let me know if this is not the right place to ask.
I just completed 11 courses of the “Scientific Computing with Python”. In the begin I was slow to solve each tasks but then I started speed up a bit while I was learning…and this is very good.
Now, I am stuck on the 12th courses called “learn Special Methods by Building a Vector Spece” step n. 6:
questions: what I have to learn to be able to understand how to get the sum of the squared components?
Your code so far
# User Editable Region
class Vector:
def __init__(self, x, y):
self.x = x
self.y = y
def norm(self):
norm = Sum(1, n+1**2)
return norm
# User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Challenge Information:
Learn Special Methods by Building a Vector Space - Step 6
Hey, here you have two components, self.x
and self.y
. You need to calculate the square of each component and sum them together.
What is blocking you?
Thank you Dario…I am not able to traslate the ||a|| forumla to python code to make the sum.
What part of that formula is causing you issues?
That formula is saying to take the square of each component, add it to the other squares (in your case the other one, since you have two components) and calculate the square root of that sum.
What part of this computation is causing you issues?
From the previous projects you should have already used sum()
and values()
(it’s okay if you don’t remember and absolutely normal, things need practice) while vars()
is taught in this project in a following step.
The answer you found is a generic application of that formula that you are going to build later on in this project. The answer here was much simpler.
Thank you Dario…I need more practice and learning if the answer here was much simpler.
If you were able to proceed to the following step you should be able to see what I mean by “much simpler”. Does it make sense to you?
‘sum’ is a fancy way to say ‘add’. Do you remember how to add quantities in Python?
Actually, I was no able to proceed. Even thinking what I learned so far did not help then I search in internet to learn by example and it did not help either. Then I found the solution and I paste in the step and I am feeling very bad. Probably, I need to think in a more creative way and logically. Also, I am in trouble with the time management: sometimes I insist for days to the same steps to try to solve it by myselft before asking you for help…How long I should keep going before to give it up?? If I do not proceed with some kind of speed I am getting frustrated thinking that it is just time consuming.
sum() is easy. What is inside sum I found difficult to make. I hope one day I will get there. Thank you…
I think you are not quite understanding the Step
You are overthinking this.
You have two components: self.x
and self.y
You need to calculate the square of each component (use the **
operator to elevate each component to the power of 2)
Add together the squares (use the +
operator)
Calculate the square root of the previous addition. You can use either the **
operator or math.sqrt()
.
This is a mathematical expression and you can break it down into smaller pieces. You don’t need fancy stuff to get to the result.
I hope this help.
2 Likes
is my approach wrong? does this line of code make any sense??
return math.sqrt(self.x2 + self.y2)
It does make sense. Do you still have any doubts?
am glad that make sense…I need to make some changes as the code doesn’t pass… 
What are you getting? Please share the updated code.
return math.sqrt(self.x**2 + self.y**2)
the above code doesn’t pass
Jeremy and Dario you were right “I did not really get the Step 6 and I was overthinking this”…I was intimidated about the ||a|| formula described in the Step.
The code pass after adding **0.5 and after reading this: formula distance = (x2 + y2) ** 0.5 from this site: A little Python and a Little Math - Python Help - Discussions on Python.org
Thank you so much. Grazie e a presto
1 Like