LP3THW EX25; Problem with last two functions

Hello Gang,

I am having some trouble getting the the final two functions in EX25 two work as shown in the book. I can complete all of the steps before in python running in the shell, but the last two functions don’t return anything. I was able get it them to return properly by adding a return line to each of them, but I would really like to understand what mistake I am making when trying to use the solution in the book. Thanks!!

having issues with print_first_and_last(sentence) and print_first_and_last_sorted(sentence)

Here is what I have with the lines from the book commented out.

output from terminal for book solution (with a few typos )

output from my modified solution
Screenshot from 2020-10-09 14-00-27

The last two are not working as shown in the book because they are not shown as in the book.
I changed mine to #print_first_word(words) and added return print_first_word(words), print_last_word(words) and it did the same, which is nothing.
calling the function and not returning it works here for me.

Try retyping exactly as in the book, even if it means starting over. That’s something Mr. Shaw recommends sometimes. It may work, if not then repost with [code] and someone with more knowhow can help break it down for you (us).

easier to copy code if its not in a screenahot.

@dragonazz Thanks! I was wondering how other folks were doing that.

Found my mistake. I had the return command on lines 13 and 18 when I should have used print().

1 Like

Great, looks like you got this solved and yes to post code do this:

[code]
# your code here
[/code]

Or this:

```
# your code here
```

Either one works.

A free service run by Zed A. Shaw for learncodethehardway.org.