Answered You can hire a professional tutor to get the answer.

QUESTION

I cannot figure out why the below code does not work. I dont think my class input is being stored to the defined list but am not sure. Also, when I...

I cannot figure out why the below code does not work. I dont think my class input is being stored to the defined list but am not sure. Also, when I try and open a .txt file nothing happens. I get the feeling this is because the list is not properly updating with the user provided inputs. Can you help me out?

Thanks!

class Home:

  def __init__(self): 

    self.__squarefeet = 0 

    self.__address = ''

    self.__city = ''

    self.__state = ''

    self.__zipcode = 0

    self.__modelname = ''

    self.__salestatus = ''

  def addNewHome(self): #10

    self.__squarefeet = int(input('Please enter the square footage of the home: '))

    self.__address = input('Enter the address: ')

    self.__city = input('Enter the nearest city: ')

    self.__state = input('Enter the state: ')

    self.__zipcode = int(input('Enter the zip code: '))

    self.__modelname = input('Enter the model name: ')

    self.__salestatus = input('Enter the sales status (For Sale, Available, Under Contract, Contingent): ')

  def removeHome(self): #20

    self.__squarefeet = 0

    self.__address = ''

    self.__city = ''

    self.__state = ''

    self.__zipcode = 0

    self.__modelname = ''

    self.__salestatus = ''

    print('Home successfully removed n')

  def updateHome(self): #30

    self.__squarefeet = int(input('Please enter the updated square footage of the home: '))

    self.__address = input('Please enter the updated address of the home: ')

    self.__city = input('Please enter the updated closest city to the home: ')

    self.__state = input('Please enter the updated state of the home: ')

    self.__zipcode = input('Please enter the updated zipcode of the home: ')

    self.__modelname = input('Please enter the updated model of the home: ')

    self.__salestatus = input('Please enter the updated for-sale status of the home (For sale, Available, Under Contract, Contingent): ')

    print('Record updated n')

  def getSquareFootage(self): #40

    return self.__squarefootage

  def getAddress(self):

    return self.__address

  def getCity(self):

    return self.__city

  def getState(self): #50

    return self.__state

  def getZipCode(self):

    return self.__zipcode

  def getModelName(self):

    return self.__modelname

  def getSaleStatus(self): #60

    return self.__salestatus

housingList = ['']

xx = 0

aa = 0

bb = 0

while True: #65

  print('Enter 1 = Create a new home record')

  print('Enter 2 = Update a home record')

  print('Enter 3 = Remove a home record')

  print('Enter 4 = Save a record to a text file')

  print('Enter 5 = Exit')

  enteredNumber = int(input('Please enter an option: n'))

  if enteredNumber == 1: #75

    xx = Home()

    xx.addNewHome()

    housingList.append(xx)

    print(housingList)

  elif enteredNumber == 2:

    address = input('Enter the updated address: n')

    check = -1

    for aa in range(len(Home)):

      if Home[aa].getAddress() == address:

        check == aa

        break

      else:

        print('Sorry, that address was not found: n')

      if(check != -1):

        Home[check].updateHome()

  elif enteredNumber == 3:

    address = input('Enter an address to remove: n')

    check = -1

    for aa in range(len(Home)):

      if Home[aa].getAddress() == address:

        check = aa

        break

      if(check != -1):

        Home[check].removeHome()

        del Home[check]

      else:

        print('Sorry, that address was not foundn')

  elif enteredNumber == 4:

    File = open('Inventory.txt','w')

exportedFile.write('Address,SquareFeet,City,State,ZipCode,ModelName,SafeStatus'+'n')

for bb in range(len(Home)):

    exportedFile.write(str(Home[BB].getAddress())+',')

    exportedFile.write(str(Home[BB].getSquareFeet())+',')

    exportedFile.write(str(Home[BB].getCity())+',')

    exportedFile.write(str(Home[BB].getState())+',')

    exportedFile.write(str(Home[BB].getZipcode())+',')

    exportedFile.write(str(Home[BB].getModelName())+',')

    exportedFile.write(str(Home[BB].getSaleStatus())+'n')

    print('Your file has been createdn')

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question