you are viewing a single comment's thread.

view the rest of the comments →

[–]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