Note that there are some explanatory texts on larger screens.

plurals
  1. POThe 'import' key in Zed's Learn Python the hard way Exercise 25
    primarykey
    data
    text
    <p>I'm having trouble importing my code into the python interpreter (powershell). I open python through powershell and when I type in "import ex24" simply nothing appears, this is using the code I copy and pasted from his site (Just to be sure):</p> <pre><code>def break_words(stuff): """This function will break up words for us.""" words = stuff.split(' ') return words def sort_words(words): """Sorts the words.""" return sorted(words) def print_first_word(words): """Prints the first word after popping it off.""" word = words.pop(0) print word def print_last_word(words): """Prints the last word after popping it off.""" word = words.pop(-1) print word def sort_sentence(sentence): """Takes in a full sentence and returns the sorted words.""" words = break_words(sentence) return sort_words(words) def print_first_and_last(sentence): """Prints the first and last words of the sentence.""" words = break_words(sentence) print_first_word(words) print_last_word(words) def print_first_and_last_sorted(sentence): """Sorts the words then prints the first and last one.""" words = sort_sentence(sentence) print_first_word(words) print_last_word(words) </code></pre> <p>When he executes it he gets this:</p> <pre><code>&gt;&gt;&gt; import ex25 &gt;&gt;&gt; sentence = "All good things come to those who wait." &gt;&gt;&gt; words = ex25.break_words(sentence) &gt;&gt;&gt; words ['All', 'good', 'things', 'come', 'to', 'those', 'who', 'wait.'] &gt;&gt;&gt; sorted_words = ex25.sort_words(words) &gt;&gt;&gt; sorted_words ['All', 'come', 'good', 'things', 'those', 'to', 'wait.', 'who'] &gt;&gt;&gt; ex25.print_first_word(words) All &gt;&gt;&gt; ex25.print_last_word(words) wait. &gt;&gt;&gt; wrods Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; NameError: name 'wrods' is not defined &gt;&gt;&gt; words ['good', 'things', 'come', 'to', 'those', 'who'] &gt;&gt;&gt; ex25.print_first_word(sorted_words) All &gt;&gt;&gt; ex25.print_last_word(sorted_words) who &gt;&gt;&gt; sorted_words ['come', 'good', 'things', 'those', 'to', 'wait.'] &gt;&gt;&gt; sorted_words = ex25.sort_sentence(sentence) &gt;&gt;&gt; sorted_words ['All', 'come', 'good', 'things', 'those', 'to', 'wait.', 'who'] &gt;&gt;&gt; ex25.print_first_and_last(sentence) All wait. &gt;&gt;&gt; ex25.print_first_and_last_sorted(sentence) All who </code></pre> <p>Also, when I manually type out the code like I usually do, I get this error. I can't to seem what mistake I made:</p> <blockquote> <blockquote> <blockquote> <p>import ex25 Traceback (most recent call last): File "", line 1, in File "ex25.py", line 1 SyntaxError: Non-ASCII character '\xff' in file ex25.py on line 1, but no encoding declared; eps/pep-0263.html for details</p> </blockquote> </blockquote> </blockquote> <p>This is my manual copy (ex25):</p> <pre><code>def break_words(stuff): """This function will break up words for us.""" words = stuff.split(' ') return words def sort_words(words): """Sorts the words""" return sorted (words) def print_first_word(words): """Prints the first word after popping it off""" word = words.pop(0) print word def print_last_word(words): """Prints the last word after popping it off""" word = words.pop(-1) print word def sort_sentence(sentence): """Takes in a full sentence and returns the sorted words.""" words = break_words(sentence) return sort_words(words) def print_first_and_last(sentence): """Prints the first and last words of the sentence.""" words = break_words(sentence) print_first_word(words) print_last_word(words) def print_first_and_last_sorted(sentence): """Sorts the words then prints the first and last one.""" words = sort_sentence(sentence) print_first_word(words) print_last_word(words) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload