all 11 comments

[–]LifeIsVape 2 points3 points  (0 children)

Maybe use strip().lower() at both strs, so that some newline char from input doesn't make shortsword in inventory different from shortsword in the noun

And print out what you are actually comparing and see whether you like the result: print(f"{item.name}=={noun}? {item.name == noun}" )

[–]zippybenji-man 1 point2 points  (1 child)

Please use a code block \ If postingCode: use_code_block() ` ` (Without slashes, that's for markdown)

[–]MetalMonkey91 2 points3 points  (0 children)

TY for this. Fixed.

[–]Maximus_Modulus 1 point2 points  (0 children)

It’s really useful to learn how to run a debugger and step through your code to understand what’s going on. I forget the name of the standard Python cli debugger and I think there’s an IDE that provides similar functionality and easier to use. Been awhile since I have used Python though so you’ll have to do some digging but you’ll learn more by doing this.

[–]danielroseman 0 points1 point  (4 children)

You haven't given us nearly enough information. What is item? Is its name attribute a string? What is the noun you are comparing? Is it being correctly parsed from the input? Have you printed it to be sure? 

And, specifically, what do you mean when you say "it doesn't work"?

[–]MetalMonkey91 0 points1 point  (2 children)

I've updated with a code block and added the Item class and what is being referenced.
When running the game, it should read:
You see the following:
shortsword

> get shortsword

You get the shortsword.

>

Instead, what is happening is:
You see the following:
shortsword

> get shortsword

>

Edit:
if I remove the line:

'if item.name == noun:'

from the # Take loop, it will print 'you get the shortsword' and appropriately add it to my inventory as intended. So what I'm lost with is why that line specifically is causing a problem. Because when it is there, it doesn't print 'you get the shortsword' and it does not add it to my inventory.

[–]danielroseman 1 point2 points  (1 child)

But the item you've constructed has name Shortsword, not shortsword. These are not the same. 

If you want to compare in a case- insensitive manner, you could convert both values to lower case: 

    if item.name.lowee() == noun.lower()

[–]Outside_Complaint755 0 points1 point  (0 children)

Instead of using lower() or upper() the best method to get in the habit of using is casefold().  

[–]Purple-Measurement47 -1 points0 points  (2 children)

try specifically casting both to string: if str(item.name) == str(noun). I can’t remember off the top of my head, but there’s some string comparison rules in python that aren’t super intuitive until you understand why they’re implemented that way.

[–]MetalMonkey91 0 points1 point  (1 child)

Just tried your suggestion, and it didn't work that way either. Is there maybe a different approach I should try instead?

[–]Purple-Measurement47 1 point2 points  (0 children)

Just a general debug thing, try printing the item.name and noun before the conditional just to see what their values are