####### Unit Five Assignment One
####### Pool Ball Appilication
######## Karthik Kuchimanhi
######## Unit Five Assignment One
######## Pool Ball Representation
from math import sqrt
class ball:
#### Constructor which accepts 4 variables and self)
def __init__(self,number,color,isStriped,location):
self.number = number
self.color = color
self.isStriped = isStriped
self.location = [0,0]
#### loop to set parameters of location[0]
if location[0] >= 0 and location[0] <= 1:
self.location[0] = location[0]
else:
self.location[0] = 0.5
#### loop to set parameter of location[1]
if location[1] >= 0 and location[1] <= 2:
self.location[1] = location[1]
else:
self.location[1] = 0.5
#### method #1: Distance - Find the distance of a ball to the coordinates given
#### sqrt((y1-y2)^2 + (x1-x2)^2)
def Distance(self,x2,y2):
x1 = self.location[0]
y1 = self.location[1]
return sqrt((y1-y2) ** 2 + (x1-x2) ** 2)
#### method #2: Set the location of a ball to the coordinates given. This
function should also check
#### if the coordinates given are out of bounds or not and do nothing if the
given coordinates are.
def setLocation(self, newLocation):
#### loop to set parameters of newLocation[0]
if newLocation[0] >= 0 and newLocation[0] <= 1:
self.location[0] = newLocation[0]
else:
self.location[0] = 0.5
#### loop to set parameters of newLocation[1]
if newLocation[1] >= 1 and newLocation[1] <= 2:
self.location[1] = newLocation[1]
else:
self.location[1] = 0.5
#### output method
This study source was downloaded by 100000850872992 from CourseHero.com on 04-08-2023 16:39:32 GMT -05:00
https://www.coursehero.com/file/134525719/poolball2py/