Вот мой код: синтаксическая ошибка находится в строке 18. Я пытаюсь понять, почему я получаю эту ошибку.
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
# Create some charges
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
# Generate arrows at random locations
random.seed(1234) # Specify a random seed
n = 500
for i in range(n):
x = random.uniform(-4 4)
y = random.uniform(-4,4)
z = random.uniform(-4,4)
pos = vector(x,y,z)
# Make sure pos is not too close to both positive and negative charge
if abs(pos - charge1.pos) > 1 and abs(pos - charge2.pos) > 1:
# Create an arrow if it's far enough from both charges
a = arrow(pos=pos, axis= Efield(pos, charge1) + Efield(pos,charge1))
Подробнее здесь: https://stackoverflow.com/questions/425 ... -it-python
Неверная синтаксическая ошибка, но я не могу ее обнаружить? (Питон) ⇐ Python
Программы на Python
-
Anonymous
1731264896
Anonymous
Вот мой код: синтаксическая ошибка находится в строке 18. Я пытаюсь понять, почему я получаю эту ошибку.
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
# Create some charges
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
# Generate arrows at random locations
random.seed(1234) # Specify a random seed
n = 500
for i in range(n):
x = random.uniform(-4 4)
y = random.uniform(-4,4)
z = random.uniform(-4,4)
pos = vector(x,y,z)
# Make sure pos is not too close to both positive and negative charge
if abs(pos - charge1.pos) > 1 and abs(pos - charge2.pos) > 1:
# Create an arrow if it's far enough from both charges
a = arrow(pos=pos, axis= Efield(pos, charge1) + Efield(pos,charge1))
Подробнее здесь: [url]https://stackoverflow.com/questions/42581434/invalid-syntax-error-but-i-cant-spot-it-python[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия