Question
1. When I run the code (http://codepad.org/kAADoUks), I get an error that 1 argument is missing for the line 129.
“question, answer = convert(snippet, phrase)”
I checked the code umpteen times, but I don’t know how to fix it.
What am doing wrong?
-
How does Python know that the code can accept more than 2 arguments on the commandline
-
Is convert(snippet, phrase) a pre-defined Python function?
-
What are these signs “###”, “*“? How are they called in Python?
are they placeholders?
-
“snippet” is not declared in the code as the population/list WORDS.
How does Python interpreter know that “snippet” refers to the list WORDS?
Is “snippet” a special Python built-in element? -
“for i in range(0, snippet.count(“@@@”)):” (line 75)
There are no “###”, ““, “@@@” signs in the URl FILE:
How is Python interpreter able to count the number of “###” or “” when there are none in the source file? -
How does the code in line 85 work?
“for sentence in snippet, phrase:”
Is “sentence” looping through 2 different list?
I don’t see anywhere in the code that “snippet” and “phrase” are defined as lists. -
The variables “question” and “answer” have the same values. What is the purpose of the if-clause in line 135?
Learn code the hard way.
Isn’t it all in the name already?
to answer some of your questions in the spirit of good will:
python doesn’t know, the code in question should and sort of does
check number of arguments
no, convert is not a pre-defined function in Python
“#” is a number sign, also called hash key, they are used for
comments in Python, but in this case they are just part of string
data, I suppose it’s your homework to fill in these.
snippet is not any special name in Python
your job to figure out I suppose
code on line 85 loops through only 2 items, snippet and phrase, code
like
for i in x, y: foo(i)is just shorthand forfoo(x); foo(y).you are correct that in this case it’s kindof bogus. I suppose it’s
your homework to correct this code so that it actually does
something useful. it’s called learn code the hard way for a reason,
right?
huh? 135 or 137?
the exception that you did not ask about, most likely it was a
temporary network error, I don’t get exception like that.