Ex 48 int and errors

I’m stuck on exercise 48. I can’t figure out how to get the integers and error functions to pass the nosetests.

Here is my code so far:

lexicon = {
	"north": "direction",
	"south": "direction",
	"east": "direction",
	"west": "direction",
	"go": "verb",
	"kill": "verb",
	"eat": "verb",
	"the": "stop",
	"in": "stop",
	"of": "stop",
	"bear": "noun",
	"princess": "noun",

}

def scan(sentence):
	results = []
	words = sentence.split()
	for word in words:
		word_type = lexicon.get(word)
		results.append((word_type, word))
	return results 

Thanks for your help.

Hello @tzidan.
A friend who helped me with this exercise told me this:
You need a function for the dictionary, a function for integers( try except).
The rest of user input is error.

These three ”elements” can be processed with a loop with if-statements.

Hey @tzidan, so first up you can wrap your code with this:

[code]
# my python here
[/code]

And make it nicer for people to read. I already did it for you on this post, but remember it for the next one.

Now, the trick is to realize that if something is a number it’ll convert no problems, but if it’s not then you get an error. That means, you can attempt to convert, and if it fails, then assume that what you’ve received is not a number and is some word in your lexicon. So, if I wrote this as steps it’d be:

try:
    number = int(word)
    # it's a number so put it in as a number
except:
    # it's not a number so treat it like a word

You can also write a little function that does this conversion, but that is the simplest way.

Thanks for all your help and feedback!