0

I am working on a python program with for loops, dictionary, and items. I have an array from a class that supposedly has the items for the dictionaries however each time I run the code I get an error and I have change my code several time and I cant get it to output the right result or to even run properly. In contrast I can't change anything above my for loops and was wondering if i should input a dictionary. However it is stated that the dictionary should be in the DepartmentManager in the departments{} array. Therefore, i would like some help in trying to make my for loop run correctly without an error.

Here are the instructions for the first for loop: Create a for in loop to loop over the items in the dictionary stored in the departments attribute of the DepartmentManager object

Here is the 2nd for loop instructions: Create another for in loop inside the first loop. This loop will be used to print out the assets that belong to the Department if the asset value is less than $2,000

class Department:
def __init__(self, departmentSupervisor):
    self.departmentSupervisor = departmentSupervisor

    self.departmentAssets =[]    

class DepartmentAsset:
def __init__(self, assetName, quantity, expectedLifeSpan, AssetValue):
    self.assetName = assetName
    self.quantity = quantity
    self.expectedLifeSpan = expectedLifeSpan
    self.AssetValue = AssetValue

class DepartmentManager:
def __init__(self):
    self.departments = {}

deptManager = DepartmentManager()
mktDept = Department("Jamie Doe")
maktDeptAsset1 = DepartmentAsset ("desk", 5000, 2, 10)
maktDeptAsset2 = DepartmentAsset ("computer", 1500, 5, 5)
mktDept.departmentAssets.append(maktDeptAsset1)
mktDept.departmentAssets.append(maktDeptAsset2)

financeDept = Department("Ryan Doe")
financemaktDeptAsset1 = DepartmentAsset ("chair", 500, 2, 10)
financemaktDeptAsset2 = DepartmentAsset ("calculator", 500, 3, 5)
financeDept.departmentAssets.append(financemaktDeptAsset1)
financeDept.departmentAssets.append(financemaktDeptAsset2)

deptManager.departments["marketing"] =  mktDept
deptManager.departments["financing"] =  financeDept

for key, value in deptManager.departments():
    print(mktDept.departmentSupervisor + "is in charge of the fowwling " +
      departmentAsset.getkey() + " department and the following assets less than $2000." )
    for mktDept in deptManager.departments["Marketing"]:
        print (mktDept.departmentAssets.quantity + " " + 
               mktDept.departmentAssets.assetName + "at $" + 
               mktDept.departmentAssets.AssetValue + " each. This asset is expected to last for " +
               mktDept.departmentAssets.expectedLifeSpan + "to the values stored in the DepartmentAsset belonging to the Department")

TypeError: 'dict' object is not callable **This is the error I keep getting at the end of my code or something similar to this

Leeda Vang
  • 13
  • 3
  • `for key, value in deptManager.departments.items():` – azro Mar 30 '20 at 19:03
  • Does this answer your question? [Iterating over dictionaries using 'for' loops](https://stackoverflow.com/questions/3294889/iterating-over-dictionaries-using-for-loops) – azro Mar 30 '20 at 19:03

1 Answers1

0

Instead of

for key, value in deptManager.departments():

you want

for key, value in deptManager.departments.items():