In this part of the lab, you will implement a City class. Objects of this class have instance variables for the city's name (a string) and population (an integer). You will implement the following methods:
""" Program: Lab 13 Author: Your name Define and test a basic City class. """ import sys class City: pass def main(): tokyo = City('Tokyo', 13189000) mexico_city = City('Mexico City', 8857188) main()
print(tokyo) print(mexico_city)Run your program. You should see an output that looks something like
<__main__.City object at 0xe5ec10> <__main__.City object at 0xe5ecd0>This is because we haven't told Python how to represent a city as a string.
Tokyo (pop. 13189000)or
Mexico City (pop. 8857188)Rerun your program. You should see the two lines of output above.
# Print whichever city is larger print('The larger city is:') if mexico_city < tokyo: print(tokyo) else: print(mexico_city)Run your program. It should fail because we haven't told Python what it means for one City object to be smaller than another.
def __lt__(self, other): # Return True if the population of self is less than # the population of other and return False otherwise pass
Tokyo (pop. 13189000) Mexico City (pop. 8857188) The larger city is: Tokyo (pop. 13189000)