嘿,是不是可以調用一個函數值,而不是調用整體功能的?作爲,如果我叫整體功能,這將不必要地運行它,我不想。 例如:變量和函數
def main():
# Inputing the x-value for the first start point of the line
start_point_x_1()
# Inputing the x-value for the 2nd end point of the line
end_point_x_2()
# The first output point calculated and printed
first_calculated_point()
def start_point_x_1():
return raw_input("Enter the x- value for the 1st " +
"start point for the line.\n")
def end_point_x_2():
return raw_input("Enter the x- value for the 2nd " +
"end point for the line.\n")
def first_calculated_point():
x0 = int(start_point_x_1())
a = int(end_point_x_2()) - int(start_point_x_1())
lamda_0 = 0
x = x0 + (lamda_0)*a
main()
上述工程的代碼,但是當我到達功能first_calculated_point
,當我計算x0
,函數start_point_x_1()
運行again.I試圖存儲等功能「例如x1 = raw_input("Enter the x- value for the 1st " + "start point for the line.\n")
作用下start_point_x_1()
但是當我所說的變量x1
在x0 = x1
,他們說沒有定義x1
。有什麼辦法來存儲函數的值,並調用它而不是調用整個函數?
您的代碼不可能工作?縮進似乎是錯誤的(因爲函數定義下面沒有縮進行)。至少,您需要在那裏使用「傳遞」語句。請重新格式化代碼,使其看起來與您正在運行的程序完全相同。 – richardolsson 2010-01-01 13:04:50
對不起,我忘了添加打印x – blur959 2010-01-01 13:34:27