Python 询问输入时代码中断的原因是什么?

Python 询问输入时代码中断的原因是什么?,python,function,physics,Python,Function,Physics,嗨,我是python新手,正在从事一个小项目: 我想写一个程序来提供一个直接抛向空中的球的高度信息。程序应请求输入初始高度h英尺和初始速度v英尺/秒。t秒后球的高度为h+vt-16t2英尺。程序应执行以下两个计算: (a) 确定球的最大高度。注意:球将达到最大值 v/32秒后的高度。 (b) 大致确定球何时落地。提示:每隔.1秒计算一次高度,并确定高度何时不再为正数。 应使用名为getInput的函数获取h和v的值,该函数应调用名为isValid的函数,以确保输入值为正数。(a)和(b)项任务均

嗨,我是python新手,正在从事一个小项目:

我想写一个程序来提供一个直接抛向空中的球的高度信息。程序应请求输入初始高度h英尺和初始速度v英尺/秒。t秒后球的高度为h+vt-16t2英尺。程序应执行以下两个计算:

(a) 确定球的最大高度。注意:球将达到最大值 v/32秒后的高度。 (b) 大致确定球何时落地。提示:每隔.1秒计算一次高度,并确定高度何时不再为正数。 应使用名为getInput的函数获取h和v的值,该函数应调用名为isValid的函数,以确保输入值为正数。(a)和(b)项任务均应由职能部门执行

  def getInput():
        h = int(input("Enter the initial height of the ball: "))
        v = int(input("Enter the initial velocity of the ball: "))
        isValid(h,v)

    def isValid(h,v):
        if (h<= 0):
            print("Please enter positive values")

        elif(v<= 0):
            print("Please enter positive values")

        else:
            height = maxHeight(h,v)
            print("The maximum height of the ball is", height, "feet.")
            groundTime = ballTime(h,v)
            print("The ball will hit the ground after approximately", groundTime, "seconds.")


    def maxHeight(h,v):
        t = (v/32)
        maxH = (h + (v*t) - (16*t*t))
        return maxH


    def ballTime(h,v):
        t = 0.1
        while(True):
            ballHeight = (h + (v*t) - (16*t*t))
            if (ballHeight <= 0):
                break
            else:
                t += 0.1

        return t

    getInput()

看起来你在用IPython?在此之前,您可能必须去掉elif和if主体之间的空格。它似乎就在那里完成了对这行的解释,然后,如果您逐个输入这些行,Python解释器将停止解释

 def getInput():
        h = int(input("Enter the initial height of the ball: "))
        v = int(input("Enter the initial velocity of the ball: "))
        isValid(h,v)

    def isValid(h,v):
        if (h<= 0):
            print("Please enter positive values")
        elif(v<= 0):
            print("Please enter positive values")
        else:
            height = maxHeight(h,v)
            print("The maximum height of the ball is", height, "feet.")
            groundTime = ballTime(h,v)
            print("The ball will hit the ground after approximately", groundTime, "seconds.")


    def maxHeight(h,v):
        t = (v/32)
        maxH = (h + (v*t) - (16*t*t))
        return maxH


    def ballTime(h,v):
        t = 0.1
        while(True):
            ballHeight = (h + (v*t) - (16*t*t))
            if (ballHeight <= 0):
                break
            else:
                t += 0.1
        return t

    getInput()
def getInput():
h=int(输入(“输入球的初始高度:”)
v=int(输入(“输入球的初始速度:”)
isValid(h,v)
def有效(h,v):

如果(hI)在我的系统上运行,您能发布错误吗?@ari victor File“”,第1行elif(vAgreed-此处运行正常:我没有收到输出,它只运行正常@rgk
 def getInput():
        h = int(input("Enter the initial height of the ball: "))
        v = int(input("Enter the initial velocity of the ball: "))
        isValid(h,v)

    def isValid(h,v):
        if (h<= 0):
            print("Please enter positive values")
        elif(v<= 0):
            print("Please enter positive values")
        else:
            height = maxHeight(h,v)
            print("The maximum height of the ball is", height, "feet.")
            groundTime = ballTime(h,v)
            print("The ball will hit the ground after approximately", groundTime, "seconds.")


    def maxHeight(h,v):
        t = (v/32)
        maxH = (h + (v*t) - (16*t*t))
        return maxH


    def ballTime(h,v):
        t = 0.1
        while(True):
            ballHeight = (h + (v*t) - (16*t*t))
            if (ballHeight <= 0):
                break
            else:
                t += 0.1
        return t

    getInput()