所以我对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