对于这个程序,我正在使用 python。
我应该将机器人移动到随机位置并将其旋转 360 度。我必须将所有三个光传感器的 15 个读数分配给三个不同的列表。
然后我必须计算每个传感器的光值的平均值,然后确定每个传感器的最大值和最小值。
然后我必须计算并显示所有三个传感器的光值的平均值,并让它宣布其周围的平均光值以及它是否太亮或太暗。
我相信我已经完成了这一切,但是我的程序不起作用。例如,我的机器人在随机位置移动,然后旋转 360 度,但随后程序停止了,我不知道为什么。
出现一个错误,上面写着:
max() arg is an empty sequence
如果有人可以帮助我弄清楚我做错了什么,那就太好了!太感谢了!!!
这是我的程序:
from myro import *
init("simulator")
def pressC():
entry = " "
while(entry != "c"):
entry = raw_input("Press c to continue: ")
def movement():
rightSensor = []
centerSensor = []
leftSensor = []
return rightSensor
return centerSensor
return leftSensor
for index in range(1,15):
rightSensor.append(getLight("right"))
centerSensor.append(getLight("center"))
leftSensor.append(getLight("left"))
def average():
rightSensor = []
centerSensor = []
leftSensor = []
sumRight = 0
sumCenter = 0
sumLeft = 0
for index in range(len(rightSensor)):
sumRight = sumRight + rightSensor[index]
averageRight = sumRight / 15
for index in range(len(centerSensor)):
sumCenter = sumCenter + centerSensor[index]
averageCenter = sumCenter / 15
while averageCenter > 100:
speak("Its too dark. I need light")
else:
speak("Its so bright")
for index in range(len(leftSensor)):
sumLeft = sumLeft + leftSensor[index]
averageLeft = sumLeft / 15
max(rightSensor)
min(rightSensor)
max(centerSensor)
min(centerSensor)
max(leftSensor)
min(leftSensor)
print "Left Avg: " + str(averageLeft), "Max: " + str(leftSensor), "Min: " + str(leftSensor)
print "Center Avg: " + str(averageCenter), "Max: " + str(centerSensor), "Min: " + str(centerSensor)
print "Right Avg: " + str(averageRight), "Max: " + str(rightSensor), "Min: " + str(rightSensor)
def main():
pressC()
forward(1,1)
rotate(1)
wait(7)
stop()
movement()
average()
main()