Advertisements
Advertisements
प्रश्न
A dartboard of radius 10 units and the wall it is hanging on is represented using a two-dimensional coordinate system, with the board’s 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:
- (0, 0)
- (10, 10)
- (6, 6)
- (7, 8)
संक्षेप में उत्तर
Advertisements
उत्तर
The distance formula can be used to calculate the distance between the points where the dart hits the dartboard and the centre of the dartboard.
The distance of a point P(x, y) from the origin is given by `sqrt(x^2 + y^2)`.
To calculate the square root, the equation can be raised to the power of 0.5.
Program:
x = int(input('Enter X Coordinate: '))
y = int(input('Enter Y Coordinate: '))
dis = (x ** 2 + y ** 2) ** 0.5
#if dis is greater than 10, means that dart is more than 10 units away from the centre.
print(dis <= 10)
The output for the dart coordinates are as follows:
a) (0,0): True
b) (10,10): False
c) (6,6): True
d) (7,8): Falseshaalaa.com
Relational Operator (>,>=,<=,=,!=)
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
