A little Python and a Little Math

Hello,

I am lost with this simple topic, I am taking a intro to python course and this one topic keeps coming up and causing me to fail each individual building block. I struggle with math so please take that into consideration when reposnding.

My requirement is as follows:

create a variable to hold the x coordinate and give it a value|
create a variable to hold the y coordinate and give it a value|
create a variable that will hold the distance which is √(x2 + y 2)|
output all the values and variables calculated|

I have turned in the following:

x=10
y=10

distance=(x ** 2 + y ** 2)

print(“Disance is x to the 2nd power + y to the 2nd power”)
print(“Distance is”, distance)
print(“The value of x is”, x)
print(“The value of y is”, y)

At this point we have not learned anything about importing/importing match to be specific, everything I read online discusses importing but the instructor has not stated I am missing this nor have we learned how to import so I am under the impression that its possible without importing.


It was returned as incorrect, the response I got was as follows:

copy and paste
"This still incorrect

formula is squareroot(x(squared)+y(squared))
your distance is still incorrect"

I have been working this topic for 8 weeks now and cant seem to get ahead, any any clear, concise, and constructive guidance would be apricated but please be mindful that I am already confused so any un-necessary reworking of code will just continue to compound my confusion.

your formula for distance is incorrect. To get the distance between two points use the Pythagoras theorem. Normally you would import math.sqrt and use that but as you cannot, you can also raise to the power of 0.5 to square root. This works without needing to import anything. This would make your distance formula distance = (x2 + y2) ** 0.5 .

Note: In the future, I would recommend using stack overflow for questions like these. The community is much more active and geared toward beginner questions.

Thank you,

So using that formula I am getting a error, here is how I modified the code.

x=10
y=10

distance=(x2 + y2) ** 0.5

print(“Disance is x to the 2nd power + y to the 2nd power”)
print(“Distance is”, distance)
print(“The value of x is”, x)
print(“The value of y is”, y)

Maybe there’s some formatting issue, but the code presented was:

distance=(x**2 + y**2) ** 0.5

i.e. x to the power 2 plus y to the power 2. It is possible that by
inlining the code in the text the double asterisks were dropped from
what was presented to your eye.

Cheers,
Cameron Simpson cs@cskk.id.au

Thank you that that correct the error, I really apricate your help.