我不能在python3.3上运行matplotlib

2024-09-26 22:13:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个代码:

import random
import matplotlib.pyplot as plotttt

def simular (N):

  Nd=N
  c=0

  while Nd>(N/2-1):
      r=random.uniform(0,1)

      if r<Nd/float(N):
         Nd=Nd-1

      else:
         Nd=Nd+1

      c+=1

  return c

def main ():

   Nmax=400
   repeticiones=100

   x=[]
   y=[]

   for j in range (2,Nmax):

       promedio=0

       for i in range (0,repeticiones):
           promedio+=simular(j)

       y.append(promedio/repeticiones)
       x.append(j)

   plotttt.plot (x,y,"bo")
   plotttt.show()

main()

但当我试图通过终端运行时,下一个错误出现了:

^{pr2}$

不过,当我在空闲状态下运行它时,不会出现任何问题。思想?在


Tags: 代码inimportformaindefrangerandom

热门问题