我在参加在线课程时遇到了这个问题。正确答案是选项(C),但是,为什么我不能选择选项(A)?这两种选择之间有什么细微差别?你知道吗
--->; 假设我们想创建一个类polarbeardunder,一只喝醉的北极熊,它沿着x和y轴随机移动,向南移动时走大步,向北移动时走小步。你知道吗
class PolarBearDrunk(Drunk):
def takeStep(self):
# code for takeStep()
以下哪项是takeStep()的适当实现?你知道吗
方案A)
directionList = [(0.0, 1.0), (1.0, 0.0), (-1.0, 0.0), (0.0, -1.0)]
myDirection = random.choice(directionList)
if myDirection[0] == 0.0:
return myDirection + (0.0, -0.5)
return myDirection
方案B)
directionList = [(0.0, 0.5), (1.0, -0.5), (-1.0, -0.5), (0.0, -1.5)]
return random.choice(directionList)
选项C)
directionList = [(0.0, 0.5), (1.0, 0.0), (-1.0, 0.0), (0.0, -1.5)]
return random.choice(directionList)
选项D)
directionList = [(0.0, 1.0), (1.0, 0.0), (-1.0, 0.0), (0.0, -1.0), (0.0, -1.0)]
return random.choice(directionList)
元组上的
+
运算符(如选项A)表示串联:(0.0, 1.0) + (0.0, -0.5) == (0.0, 1.0, 0.0, -0.5)
相关问题 更多 >
编程相关推荐