Let's now apply the scientific method to a Python program which removes HTML markup.
First of all, let us write down again what we have observed so far,
what we expected, and what the output was.
If our input was foo in HTML markup, then we would expect the output foo,
and the actual output was foo, so this is just fine.
If our input was the same thing in double quotes, we would expect the double quotes
also to appear in the output, but instead we get the HTML markup still included in the output
that is the whole thing fails because of all the observations we made and from this,
we need to come up with the first hypothesis on what makes the error.
So, here a quiz. Which hypotheses are consistent with our observations so far?
Check all that apply.
Is it that double quotes are stripped from tagged input, is it that tags in double quotes
are not stripped, is it that the tag for bold is always stripped from the input,
or is it that four-letter word are stripped.
Applichiamo ora il metodo scientifico ad un programma Python che elimina il markup HTML.
Prima di tutto, scriviamo di nuovo cio' che abbiamo osservato finora,
cosa ci aspettiamo e com'era l'output.
Se l'input era foo dentro un markup HTML, ci saremmo aspettati come output foo
e in effetti l'output era foo, quindi questo va bene.
Se il nostro input era la stessa cosa ma con i doppi apici, ci saremmo aspettati che i doppi apici
fossero presenti nell'output, ma invece trovavamo il markup HTML incluso nell'output,
cioe' il tutto non funzionava. Queste sono tutte le osservazioni che abbiamo fatto e da qui
noi dobbiamo arrivare ad una prima ipotesi su cio' che crea l'errore.
Dunque, ecco un quiz: quali ipotesi sono congrue con le nostre osservazioni fatte?
Trova quelle giuste:
i doppi apici vengono eliminati dall'input taggato, i tag tra i doppi apici
non vengono eliminatii, il tag di bold e' sempre eliminato dall'input
o vengono eliminate le parole di quattro lettere?
では科学的手法を
Pythonのプログラムに応用してみましょう
HTMLタグを削除するプログラムです
まず観察や予測そして出力が何であったかを
もう一度書き出してみます
HTMLタグの間にfooと書かれているので
出力がfooになると予測できます
実際の出力もfooでしたのでこれは問題ありません
今度は入力にダブルクォーテーションがあるので
出力にもあると予測します
しかし出力にはHTMLタグが出てしまいました
観察から結果を予測しましたが
違う結果になりましたね
何がエラーを起こしているのか
まず仮説を立ててみましょう
ここで小テストです
今のところどの仮説が観察と一致していますか?
正しいものをすべて選びましょう
タグつき入力から
ダブルクォーテーションが削除されたこと?
ダブルクォーテーション内のタグが削除されないこと?
<b>タグが入力から常に削除されること?
タブー語が削除されること?
现在我们就将科学方法应用到删除HTML标签的Python程序中。
首先,我们写下我们目前观察到的情况,
我们预期的结果,以及实际的输出,
如果我们的输入是带HTML标签的foo,预期输出是foo,
实际输出是foo,一切正常。
如果输入是带双引号的上一条内容,预期双引号
也会出现在输出中,但结果HTML标签还包含在输出里,
就失败了,因为我们观察到的结果不符合预期。据此,
我们提出第一个假设--是什么产生了错误。
先来个小测。哪个假设和我们的观察相匹配?
请选择符合的选项。
一,双引号从带标签的输入中删掉了,二,双引号中的标签
没被删掉,三,粗体标签总会从输入中删掉,
四、这四个字母的单词被忽略了。