这是我的代码,语法错误在第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
答案 0 :(得分:2)
在:
def Effield(pos, charge)
你也错过了一行逗号:
x = random.uniform(-4 4)
应该是
x = random.uniform(-4, 4)
此功能根本没有缩进,会抛出:
IndentationError:预期缩进块