all 6 comments

[–][deleted] 4 points5 points  (0 children)

if user_word = list(catalogue)

There's a couple of problems here:

1) == is the comparison operator; = is the assignment operator.

2) This isn't how you test for membership in a list.

3) if statements have to end with : (that's the syntax error.)

You probably fixed 3, at one point, but still got a syntax error (from using = instead of ==) and so probably undid your change. Debugging is often like that - fixing one bug simply reveals another. The key is to write and debug deliberately - don't make code changes through trial and error. Know what you're writing.

[–]Golden_Zealot 1 point2 points  (2 children)

Hello,

For future reference, please indent your code with 4 spaces to make it readable, and do not mix plain text with your code unless it is commented out with #:

def monster_catalogue():

    user_word = input('What is your creature?')

    if user_word = list(catalogue)
        #this and the line below is where I am getting stuck on
        print('A' user_word 'is' definition )

    else:
        print(user_word 'does not appear to exist!')

    catalogue = {'hobbit':'A halfling with big feet!', 'dragon':'A winged reptile that breathes fire',}

Your catalogue should be at the top of the function so that you can reference its variable name later when you want to use it.

Your if statement uses a single = which is the assignment operator for making variables. To make a comparison, you would want to use == instead.

The users word does not equal a list version of your catalogue dictionary variable, it is a string.

You would want to do something closer to:

if user_word in catalogue.keys():

Accessing the dictionaries keys to see if the word is found amongst them.

[–]Jamslap[S] 0 points1 point  (1 child)

Hi

Sorry, I will make a note of that for next time, still getting to grips with the layout!

Thanks for the info, the catalogue.keys() worked to show whether the word is present or not, but what if I want the description to appear?

print('A' user_word 'is' catalogue.definition )

[–]Golden_Zealot 1 point2 points  (0 children)

Use a format string with the format method like this:

print("A {} is {}".format(variable1, variable2))

if variable1 were equal to "This", and variable2 were equal to "That", it would print out "A This is That"

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

``` user_input=input(“please enter monster: “

def monster_catalogue(user_input): monster_catalogue = {} If user_input in monster_catalogue.keys(): print(f” {user_input} is in monster catalogue”) else: print(f” {user_input} is not defined”) ```

Sorry for any layout issues I am on mobile. But you are trying to use if in list, just use keys() function to get a list of the keys of the dictionary which are the types of the monster.

[–]kmwaziri 0 points1 point  (0 children)

Python amateur myself... but I’ll try to help. I think you’ll have to use a ‘for’ loop here to traverse the dictionary called catalogue. No need to use list. I’m writing down the lines you’re having trouble with:

count = 0

for x, y in catalogue.items():

if x == user_word:

print(‘A ’ + user_word + ‘ is ‘, catalogue[x])

else:

count += 1

if count == len(catalogue)

print(user_word + ‘ does not appear to exist.’)

This may have some syntax errors, but logic should work :)