Point Distance
Programming Interview
Easy
8 views
Problem Description
You're given {x}. Create Point class with method dist0() giving distance from origin. Output with 3 decimals.
Input Format
One line: x y.
Output Format
One number distance.
Official Solution
import sys,math
p=sys.stdin.read().strip().split()
if len(p)<2: sys.exit(0)
x=int(p[0]); y=int(p[1])
class Point:
def __init__(self,x,y):
self.x=x
self.y=y
def dist0(self):
return math.hypot(self.x,self.y)
pt=Point(x,y)
sys.stdout.write(f'{pt.dist0():.3f}')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!