Programming Examples
Python program to check whether dart hit inside board or outside
A dartboard of radius 10 units and the wall it is hanging on are represented using a two-dimensional coordinate system, with the boards center at coordinate (0,0). Variables x and y store the x-coordinate and the y-coordinate of a dart that hits the dartboard. Write a Python expression using variables x and y that evaluates to True if the dart hits (is within) the dartboard, and then evaluate the expression for these dart coordinates:
(a) (0,0)
(b) (10,10)
(c) (6,6)
(d) (7,8)
Solutions:
import math
x=int(input("Enter the Coordinate x : "))
y=int(input("Enter the Coordinate y : "))
distance=math.sqrt(math.pow(x,2)+math.pow(y,2))
if distance<=10:
  print("Within Board")
else:
  print("Outside Board ")
Output/ Explanation:
Enter the Coordinate x : 6
Enter the Coordinate y : 6
Within Board
>>>Â
=================Â
Enter the Coordinate x : 10
Enter the Coordinate y : 10
Outside BoardÂ