可能重复:
最大递归深度?
我的代码有另一个问题.我正在研究我在Vpython中的第一个程序,我必须模拟混合两种气体.首先我遇到了边界问题,但现在当球(代表气体粒子)留在边界内时,存在不同的错误.几秒钟后,我收到一个错误,该错误显示在我的函数的源代码下面.码:
def MovingTheBall(listOfBalls,position,numCell,flagOfExecution):
flag = 0
if flagOfExecution==0:
positionTmp = position
else:
positionTmp = (position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0)
for i in range( 0, len(listOfBalls) ):
if positionTmp==listOfBalls[i].pos:
flag=1
if flag==1:
return MovingTheBall(lista,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)
else:
if positionTmp[0]==0 or positionTmp[0]>=numCell or positionTmp[0]<=-numCell or positionTmp[1]>=numCell or positionTmp[1]<=-numCell:
return MovingTheBall(lista,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)
return positionTmp
Run Code Online (Sandbox Code Playgroud)
错误是:
return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)
File "gaz.txt", line 138, in MovingTheBall
return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)
File "gaz.txt", line 138, in MovingTheBall
return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)
File "gaz.txt", line 138, in MovingTheBall
return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)
File "gaz.txt", line 138, in MovingTheBall
return …Run Code Online (Sandbox Code Playgroud) 我试图在Ubuntu上运行这个 Python程序,但我收到一个错误
ImportError: No module named visual
Run Code Online (Sandbox Code Playgroud)
你们能指导我如何解决这个问题吗?
好吧,所以我在vpython中做这个微小的倒计时功能,我现在正在这样做
import time
print "5"
time.sleep(1)
print "4"
time.sleep(1)
print "3"
time.sleep(1)
print "2"
time.sleep(1)
print "1"
time.sleep(1)
print "0"
time.sleep(1)
print "blastoff"
Run Code Online (Sandbox Code Playgroud)
当然,这实际上不是我的代码,但它很好地证明了它.所以我想要做的不是打印它5 4 3 2 1 Blastoff我希望54321 Blastoff在同一条线上.我怎么会等待一秒钟并在同一行打印charecter.请让我知道,这将是一个很大的帮助
我想visual用于我的项目.我之前已经多次使用它了,一切都很好,但我最近改变了工作,所以我在以前从未使用过的机器上使用它
问题有些奇怪:当我从/visual/examples一切运行其中一个示例脚本时就好了.但是当我尝试运行一个非常简单的脚本时:
import visual
visual.sphere(pos=[0.,0.,0.],radius=1.,color=visual.color.red)
Run Code Online (Sandbox Code Playgroud)
执行需要几分钟.对于我想要使用它的项目来说,这是完全不可接受的.
我已经尝试从命令行和IPython运行这种脚本,但行为是相同的:出现一个可视窗口,Windows将窗口标记为"没有响应",然后,经过一段痛苦的长时间后,整个场景显示为预期.
这显然不是我用来调用什么IDE的问题,visual而且我对如何解决这个问题非常无能为力.如果这是重要的,我使用64位Windows(也下载64b visual)和Anaconda附带的Python发行版.
一个有趣的观察:我运行脚本的Python解释器并不忙,即我可以在视觉场景无法正确显示时执行其他命令.
任何有关如何尝试解决此问题的帮助甚至想法都将非常感激.
运行此代码时,出现错误“错误:属性'pos'必须是向量。” 我必须在某个地方写另一个向量吗?因为我在写向量
grav_force = vector(0,-object.mass*grav_field,0)
Run Code Online (Sandbox Code Playgroud)
这是我的整个代码
GlowScript 2.7 VPython
from visual import *
display(width = 1300, height = 1000)
projectile = sphere(pos = (-5,0,0),
radius = 0.1,
color = color.red,
make_trail = True)
projectile.speed = 3.2 # Initial speed.
projectile.angle = 75*3.141459/180 # Initial angle, from the +x-axis.
projectile.velocity = vector(projectile.speed*cos(projectile.angle),
projectile.speed*sin(projectile.angle),
0)
projectile.mass = 1.0
grav_field = 1.0
dt = 0.01
time = 0
while (projectile.pos.y >=0):
rate(100)
# Calculate the force.
grav_force = vector(0,-projectile.mass*grav_field,0)
force = grav_force
# …Run Code Online (Sandbox Code Playgroud) 我是Python的新手,但我真的很想制作一个可以模拟吉他弦的代码.我该怎么做呢?或者至少我将如何开始这样做?任何帮助表示赞赏!
谢谢!
编辑:
我想在播放不同的弦乐,音符等时看到声波.当两个不同的弦乐正在播放时,我也对声波感兴趣,当它们是不和谐和辅音音符时,它会如何变化.我感兴趣的另一件事是,当弦乐没有被弹拨(共鸣)时,弦乐会有时会振动.
任何帮助表示赞赏,谢谢!
我有一台运行10.7.3 Lion的MacBook Pro,默认安装了Python 2.7 64bit.我需要一个名为VPython的程序用于我所在的物理类,而VPython网站表示它不适用于64位Python.所以我想知道我的MacBook上是否有32位和64位Python 2.7,如果它们会发生碰撞或引起问题.我知道我可以做VPython的Python 3.1版本,但我认为教授给我们的大多数指令都是针对Python 2.7的.感谢您对此提供任何帮助.
基本上,我创造了质量,给了他们一些速度和动量,我试图利用重力的力量使它们相互绕轨道运行(围绕它们的质心).
from visual import *
earth = sphere(radius = 100000000)
newPlanet = sphere(pos = (3.84403*10**8, 0, 0), radius = 10000000)
earth.velocity = vector(0, 100, 0)
newPlanet.velocity = vector(0, 100, 0)
earth.mass = 2*10**30
newPlanet.mass = 1*10**30
earth.p = vector(0, earth.mass*earth.velocity, 0)
newPlanet.p = vector(0, newPlanet.mass*newPlanet.velocity, 0)
dt = 1000
r = newPlanet.pos.x
T = 1.296*10**6
G = 6.673*10**-11
while 1:
Fnet = G*((earth.mass*newPlanet.mass)/r**2)
earth.p += Fnet*dt
newPlanet.p += Fnet*dt
earth.velocity += (earth.p/earth.mass)*dt
newPlanet.velocity += (newPlanet.p/newPlanet.mass)*dt
earth.pos += earth.velocity*dt
newPlanet.pos += …Run Code Online (Sandbox Code Playgroud) 尝试在Ubuntu 11.10上使用VPython时出错.我使用Ubuntu软件中心安装了该程序.我发现的所有附加说明都是针对更旧的版本或者让我感到困惑.为了使用VPython,我需要做什么?我正在运行Python 2.7.2.
neil@neilcomp:~$ python
Python 2.7.2+ (default, Oct 4 2011, 20:06:09)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from visual import *
>>> sphere()
(python:26388): Gtk-WARNING **: Unable to locate theme engine in module_path: "pixmap",
(python:26388): Gtk-WARNING **: Unable to locate theme engine in module_path: "pixmap",
(python:26388): Gtk-WARNING **: Unable to locate theme engine in module_path: "pixmap",
(python:26388): Gtk-WARNING **: Unable to locate theme engine in module_path: "pixmap",
(python:26388): GdkGLExt-WARNING …Run Code Online (Sandbox Code Playgroud) Python抛出以下错误:
File "C:\Python27\Lib\site-packages\numpy\core\arrayprint.py", line 42
from .umath import absolute, not_equal, isnan, isinf, isfinite, isnat
ImportError: cannot import name isnat
Run Code Online (Sandbox Code Playgroud)
很奇怪,因为我找不到isnat文档。我的numpy版本是1.14.0,这似乎是唯一无法从加载的库.umath。
python ×10
vpython ×10
python-2.7 ×2
32bit-64bit ×1
3d ×1
glowscript ×1
graphics ×1
guitar ×1
importerror ×1
installation ×1
numpy ×1
pip ×1
recursion ×1
simulation ×1
ubuntu ×1