Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 if you could help me out itd be great! image text in transcribed
image text in transcribed
image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Neo4j Data Modeling

Authors: Steve Hoberman ,David Fauth

1st Edition

1634621913, 978-1634621915

More Books

Students also viewed these Databases questions