m0_56315006 2021-06-09 18:46 采纳率: 100%
浏览 13
已采纳

“class”has no attritude 有大佬可以解答一下吗

请问“class”object has no attribute 是怎么回事啊 

 

  • 写回答

3条回答 默认 最新

  • 关注
    from random import choice
    
    
    class Random_walk:
    def __init__(self):
    self.num_points = 500
    self.x_values = []
    self.y_values = []
    
    def fill_walk(self):
    x = self.num_points
    while len(self.x_values) < int(self.num_points):
    x_direction = choice([1, -1])
    x_distance = choice([0, 1, 2, 3, 4])
    x_step = x_direction * x_distance
    
    y_direction = choice([1, -1])
    y_distance = choice([0, 1, 2, 3, 4])
    y_step = y_direction * y_distance
    
    if x_step == 0 and y_step == 0:
    continue
    
    elif self.x_values == [] or self.y_values == []:
    self.x_values.append(x_step)
    self.y_values.append(y_step)
    
    else:
    next_x = self.x_values[-1] + x_step
    next_y = self.y_values[-1] + y_step
    
    self.x_values.append(next_x)
    self.y_values.append(next_y)
    
    
    import matplotlib.pyplot as plt
    
    rw = Random_walk()
    rw.fill_walk()
    plt.scatter(rw.x_values, rw.y_values, s=25)
    plt.show()
    

    把def __init__(self,num_points=500):改为def __init__(self):

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法