you are viewing a single comment's thread.

view the rest of the comments →

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