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'
import random
class colorBot(Bot): def init(self): self.q = "What's your favorite color?"
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'