【问题标题】:python Spyder interactive outputpython Spyder 交互式输出
【发布时间】:2020-12-01 23:45:00
【问题描述】:

最近我写了这段代码,试图找到一些方法来计算抛物线的积分,但这对我来说现在没有任何问题,但关键是我写的代码没有给我任何输出,这很奇怪我用spyder,代码如下:

def integrator(a,b,c):
    #a,b and c are the factors of the quadratic
    import numpy as np
    delta=((b**2)-4*a*c)
    answer1= (-b+delta)/2
    answer2=(-b-delta)/2 
    #it gets the answers of the quadratic eruation and uses them as the lower and upper bounds
    if delta<=0:
        return "this func has no real answer"
    if delta==0:
        return "this function has two equal answers"
        return  answer1
  else:
      return answer1
      return answer2
  #it also calculate the answers of the quadratic equation too
  integ_range=[]
  for i in np.arange(answer1,answer2,0.01):
      integ_range.append(i)
  for i in integ_range:
      heights=(a*(i**2))+(b*i)+c
  sum1=sum(integ_range)    
  integrate=sum1*0.01
  return (integrate)

integrator(1,2,3)

the decription of my code and the ungiven output

【问题讨论】:

  • 您根本不能返回多个答案,只会返回第一个答案。您可以返回 tuple,例如return answer1, answer2 不过。

标签: python numpy anaconda spyder anaconda3


【解决方案1】:

将变量分配给积分器:

i=integrator(1,2,-3)
print(i)

应该可以的

【讨论】:

  • 非常感谢它的工作我没有注意到代码在返回后停止执行的事实
猜你喜欢
  • 2017-05-26
  • 2011-09-13
  • 2013-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-02
相关资源
最近更新 更多