neolee / wop

零基础编程思维与实践课程《欢迎进入编程世界》主站
94 stars 79 forks source link

在think前面加 "_" 运行时会出现错误 #41

Closed ECNU2036 closed 4 years ago

ECNU2036 commented 4 years ago

import random

class colorBot(Bot): def init(self): self.q = "What's your favorite color?"

def think(self, s):
    colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'purple']
    return f"Wow, you like {s}! I like {random.choice(colors)}."

c = colorBot() c.run() 运行之后是:

What's your favorite color? indigo Wow, you like indigo! I like orange.

在think前面加 “_"之后,运行就是:

What's your favorite color? red red 而且在powershell中运行就会显示错误: AttributeError: 'HelloBot' object has no attribute 'think'

neolee commented 4 years ago

因为你有的地方改了,有的地方没改,自然就出错了。仔细看录播回放。

另外,学学如何贴代码,你的代码现在显示出来是一团糟的。把你的代码放在这样的段落中:

```python
<把你的代码放在这里>
```
ECNU2036 commented 4 years ago

老师,我没有办法把代码粘贴到上面那样的段落,这个段落里" ```python "是要打字吗?

neolee commented 4 years ago

当然啊,照着输入开头和结束行,然后代码放中间。