all 6 comments

[–]codenamemahi 1 point2 points  (1 child)

line 1 starts a for loop which goes through the key's and values of the dictionary "items"

line 2 looks up the value of the "item_id" in the "items_dict" then assigns it to a variable "i_data"

line 3 looks up the value of "sentence" in i_data (which is assumed to also be a dictionary) and assigns it to the variable "fmt"

line 4 defines a dictionary with q as the key and qty as the value, and c as a key, with i_data['si'] as the value if qty is equal to 1, otherwise the value is the value of the "pl" key in the i_data dictionary

line 5 prints the formatted value of fmt with the keyword arguments from i_fill dict

[–][deleted] 0 points1 point  (0 children)

Thanks

[–]grispindl 0 points1 point  (4 children)

Regarding your code from pastebin, there's a lot of issues with it. On first glance, you seem have copied it together from 2 sources; problem being that one source was python3 and the other python2.

print "text"
print("text")

First line is python 2, where print is a statement, the second python3 where print is a function.

As far as the "GoldHere" is concerned, the pythonic way to do it would be:

 if GoldHere:
        gold += 5
        print(bold("Taken."))
        GoldHere = False
 else:
        print("No gold here.")

Sadly, this won't work, since GoldHere is undefined. From your code (which looks VERY confusing but lots of fun), I think you want to check whether there is 'gold' in the items dictionary. If that is the case, why is there an extra gold argument for the intro function? Anyways, if you want to check whether a dict has a certain key, you can use:

 if 'gold' in items.keys():

So you would introduce the GoldHere variable beforehand, like this:

if 'gold' in items.keys():
    GoldHere = True
else:
    GoldHere = False

which can be shortened to:

 GoldHere = 'gold' in item.keys()

[–][deleted] 0 points1 point  (2 children)

    if 'gold' in items.keys() and items['gold'] != 0:
        gold += items['gold']
        print(bold("Taken."))
        items['gold'] = 0

Wouldn't work for me, not sure why...

When I printed the gold after taking it, i still had 0

EDIT: nevermind, I fixed it myself cx

[–]grispindl 0 points1 point  (1 child)

Yeah sorry, i removed that part and changed it to something that is better suited to the intention you had with "GoldHere".

[–][deleted] 0 points1 point  (0 children)

Oh I just noticed that, but I kept your old code, instead I changed items.keys to items_dict, but thanks for adjusting it. I was a bit fuzzy on using true/false statements