from Myro import * init() senses() takePicture() takePicture("color") takePicture("gray") p = takePicture() show(p) show(takePicture()) savePicture(p, "office-scene.jpg") for t in timer(30): show(takePicture()) turnLeft(0.5, 0.2) N=0 for t in timer(30): show(takePicture()) turnLeft(0.5, 0.2) N=N+1 print(N) Pics = [] for t in timer(30): pic = takePicture() show(pic) Pics.append(pic) turnLeft(0.5, 0.2) savePicture(Pics, "office-movie.gif") getLight() getLight('left') getLight(0) getLight('center') getLight(1) getLight('right') getLight(2) L, C, R = getLight() print(L) Center = getLight("center") print(Center) getBright() getBright('left') getBright(0) getBright('center') getBright(1) getBright('right') getBright(2) getBright() from Myro import * # record average ambient light values Ambient = sum(getLight())/3.0 # This function normalizes light sensor values to 0.0..1.0 def normalize(v): if v > Ambient: v = Ambient return 1.0 - v/Ambient def main(): # Run the robot for 60 seconds for t in timer(60): L, C, R = getLight() # motors run proportional to light motors(normalize(L), normalize(R)) stop() getIR() getIR('left') getIR(0) getIR('right') getIR(1) getObstacle() getObstacle('left') getObstacle(0) getObstacle('center') getObstacle(1) getObstacle('right') getObstacle(2) def main(): # Run the robot for 60 seconds for t in timer(60): L, R = getIR() # motors run proportional to IR values motors(R, L) main() [] L = [] print(L) N = [7, 14, 17, 20, 27] Cities = ["New York", "Dar es Salaam", "Moscow"] FamousNumbers = [3.1415, 2.718, 42] SwankyZips = [90210, 33139, 60611, 10036] MyCar = ["Toyota Prius", 2006, "Purple"] len(N) len(L) N + FamousNumbers SwankyZips[0] SwankyZips[1:3] 33139 in SwankyZips 19010 in SwankyZips SwankyZips SwankyZips.sort() SwankyZips SwankyZips.reverse() SwankyZips SwankyZips.append(19010) SwankyZips Cities = ["New York", "Dar es Salaam", "Moscow"] for city in Cities: print(city) range(5) for I in range(5): print(I) ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" for letter in ABC: speak(letter) sentence = "Would you have any Grey Poupon" sentence.split() N = ask("Enter a number:") print(N) getGamepadNow("axis") getGamepad("axis") getGamepadNow("button") for t in timer(10): print (getGamepad("button")) def main(): # A simple game pad based robot controller for t in timer(30): X, Y = getGamepadNow("axis") motors(X, Y) main() from urllib import * Data = urlopen("http://learn.fi.edu/weather/data/jan07.txt") print(Data.read()) getLight('left') getStall() def triple(x): # Returns x*3 return x * 3 triple(3) triple(5000) # This function normalizes light sensor values to 0.0..1.0 def normalize(v): if v > Ambient: v = Ambient return 1.0 - v/Ambient while not getStall(): forward(1) stop() def stuck(): # Is the robot stalled? # Returns True if it is and False otherwise. return getStall() == 1 while not stuck(): forward(1) stop()