语法错误无效,但我无法发现它? (蟒蛇)

时间:2017-03-03 14:28:21

标签: python

这是我的代码,语法错误在第18行。我很难理解为什么我会收到此错误。

<div style="background-color : yellow; padding: 15px 0px; width: 40px;">
    <div id="lineAll">
       <div id="line1"></div>
       <div id="line2"></div>
    </div>
</div>

<style>
#lineAll {
   background-color: yellow;
   height: auto;
}

#line1 {
  height: 2px;
  background-color: black;
  transform: rotate(35deg);
  width: 40px;
}

#line2 {
  height: 2px;
  background-color: black;
  transform: rotate(-35deg);
  width: 40px;
  margin-top: 20px;
}

创建一些费用

from visual import *

def Efield(pos, charge)

    """
    Calculate electric field due to point charge

    Inputs
    ======

    pos        - Position where the E field is required (vector)
    charge.pos - Position of the charge (vector)
    charge.q   - Charge (float)

    Returns
    =======

    The electric field vector
    """

    r = vector(charge.pos) - vector(pos)  # Vector from pos to chargepos

    E = float(q) * r / abs(r)**3  # Coulomb's law

    return E

在随机位置生成箭头

charge1 = sphere(pos=(0,2,0), q=1, radius=0.2, color=color.red)    # Positive charge
charge2 = sphere(pos=(0,-2,0), q=-1, radius=0.2, color=color.blue)  # Negative charge

1 个答案:

答案 0 :(得分:2)

:

之后,你错过了def Effield(pos, charge)

你也错过了一行逗号:

x = random.uniform(-4 4)

应该是

x = random.uniform(-4, 4)

此功能根本没有缩进,会抛出:

  

IndentationError:预期缩进块

相关问题