Jun-18-2020, 08:22 PM
Ok, I am reading a book automate the boring stuff, I am on the dictionaries chapter because I’m focusing on dictionaries right now maybe I should go back to for loops but,
I have a couple questions. Regarding the following code and what it is doing.
At the for loop for k,v in inventory.items() what is happening here?
At print(str(v) + ‘’ + k ) what is the ‘ ‘ empty string?
And I guess at item_total += v what is going on here as well?
I have a couple questions. Regarding the following code and what it is doing.
At the for loop for k,v in inventory.items() what is happening here?
At print(str(v) + ‘’ + k ) what is the ‘ ‘ empty string?
And I guess at item_total += v what is going on here as well?
stuff={ 'rope':1,'torch':6,'gold coins':45,'dagger':1,'arrow':12 } def display_Inventory(Inventory): print('Inventory') Item_total=0 for k,v in Inventory.items(): print(str(v)+''+k) Item_total += v print('Total number of items:' + str(Item_total)) display_Inventory(stuff)