# A robot encounters a door. If the door is locked, the robot # should be instructed to turn around. If instead the door is # unlocked, the robot should be instructed to open the door and # enter the room. Note, before entering the robot should determine # whether the light is off. If it is off, the robot should be # instructed to first turn on the light. # Get status of the door reply = input( 'Door (locked / unlocked): ' ) # Put in standard format -- all lowercase door_sensor = reply.strip().lower() print() # Based on door sensor take action if ( door_sensor == 'locked' ) : # Cannot enter -- the door is locked print( 'Turn around.' ) else : # door_sensor is 'unlocked' # We can go in # Need to get status of light sensor light_sensor = input( 'Light is (on/off): ' ) light_sensor = light_sensor.strip().lower() # call .strip() and .lower() on the light_sensor string if (light_sensor == 'on'): print( 'Enter the room.' ) else: # light_sensor is 'off' print( 'Turn on the light.' ) print('Enter the room.') # This gets printed after we turn on the light # Alternative way # if ( light_sensor == 'off' ): # print( 'Turn on the light' ) # print( 'Enter the room' ) # This gets printed at the end whether the light is on or off because # if it's off we turn on the light then enter the room and if the light is already on # we just enter the room # Can enter because the door is open and the light is on # All done # Some E school classes do work with robots though! :) # You can code up a robot and physically design it to do stuff. # Computer Engineering students get to do stuff like that and it's super cool! # But robots do work with conditional logic and concepts like the code above # just a lot more complex :)