-3
このプログラムの機能部分(def
以降のすべて)は機能しません。エラーメッセージはありません。私はZedのやり方と同じようにすべてをタイプしたと信じています。どうしましたか?python難しい方法を学ぶex 24関数が動作しない、エラーメッセージなし
print "Let's practice everything."
print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tell'
# newline and a space are put in, tab and a space are put in
# this doesn't print the poem, only stores it
poem = """
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explanation
\n\t\t where there is none
"""
print "--------------"
print poem
print "--------------"
five = 10 - 2 + 3 -6
print "This should be five: %s" % five
def secret_formula(started):
jelly_beans = started * 500
jars = jelly_beans/1000
crates = jars/100
return jelly_beans, jars, crates
# these are local variables, they are inside the function
start_point = 10000
# whatever happened to started now happens to start point
# these are global variables, they are outside the function, could be called x, y, and z
beans, jars, crates = secret_formula(start_point)
print "With a starting point of: %d" % start_point
print "We'd have %d beans, %d jars, and %d crates." (beans, jars, crates)
# reassigns with new value based on old value
start_point = start_point/10
print "We can also do that this way:"
# brings down the info from line 29
print "We'd have %d beans, %d jars, and %d crates." % secret_formula(start_point)
「secret_formula(5)」と入力しても何も起こりません。エラーメッセージも表示されません。私は別のstackoverflowの質問からこのコードの書き直しを使用してみましたが、それは私にインデントに関するエラーメッセージを与えただけです。 DEF変更(start_point): \t start_point [0] = 3 \t start_point = [1] \t変化(start_point) プリントstart_point http://stackoverflow.com/questions/15148496/python-passing-an-integer - By-reference –
@ChrisTrachte:その投稿はあなたの質問とは関係ありません。あなたは本当にそこに行く必要はありません。 *あなたが投稿したコードは、主に私が指摘した問題を除いて動作します。 –
さて、それを得ました。それは、関数の一部ではないコードのインデントを削除した後と、フォーマット演算子%を追加した後に機能しました。 –