所以我對python很陌生,但已經成功地創建了可以計算面積,體積,將攝氏度轉換爲華氏度等的程序......但是,我似乎遇到了一些麻煩用這個'斜線'程序。Python程序告訴你一條線的斜率
# A simple program which prompts the user for two points
# and then computes and prints the corresponding slope of a line.
# slope(S): (R*R)*(R*R) -> R
# If R*R is a pair of real numbers corresponding to a point,
# then slope(S) is the slope of a line.
def x1(A):
def y1(B):
def x2(C):
def y2(D):
def slope(S):
return (D-B)/(C-A)
# main
# Prompts the user for a pair of points, and then computes
# and prints the corresponding slope of the line.
def main():
A = eval(input("Enter the value of x1:"))
B = eval(input("Enter the value of y1:"))
C = eval(input("Enter the value of x2:"))
D = eval(input("Enter the value of y2:"))
S = slope(S)
print("The slope of a line created with those points\
is: {}{:.2f}".format(S,A,B,C,D))
main()
嘗試一個函數有四個參數,而不是與每一個論辯的四個*嵌套*功能https://docs.python.org/2.7/tutorial/controlflow.html#defining-functions – wwii 2014-09-21 03:04:55