Question: My code is attached as well as the problem/goal. I think Im almost there but Im new to object-oriented programming and Python in general so
File Edit Format Run Options Window Help # defines the city class description : # -each "City" object has: 1. name 2 position (x, ) l. be created . describe itself 3. calculate distance between itself and another city # -each "City" object can: import math # for calculating distance chass City: # Class definition t constructs city det --init_ (self, name in, xin, y-in); self.namename in self.xint(x in) self.yint(y in) def -str-(self) : recurn "City Name # Describes city self.name V "Inx-coordinate: "self.x "Inx-coordinate: selt.y pass # remember to delete it def distance (sels, other) distX-math.pow (self.x - other.x, 2) # Euclidean distance for rX) distY-math . pow(self.y-other. y, 2) # Euclidean distance for (y) dist ma tn.sqrt (self.x + self.y) pzint dist Total distance between cities # testing section # Used to define special va riables. name main cityone City("La Hesa", 100, 10) cityTwo-City("Carlsbad", 100, 80) print "cesting..." tor i in range (1,5): # This will allow you to enter 4 cities. cityname raw input ("Enter the name of the City:) x_coordinate raw input ("Enter the X-Coordinate of the city: ) y_coordinate raw input ("Enter the Y-Coordinate of the cicy: ") self City) self.set name in (cityname) self.setx in(x coordinate) self.set_v in (y_coordinate) # print the cities (their descriptions) # now calculate the distance between cityone and cityTwo # using the distance method t diaplay the result in some meaningtul way (i.e using some s descriptive sentence) Ln: 16 Col 26
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
