Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2014
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.73 KB | None | 0 0
  1. floor = [0]         # keeps track of which floor you're on, zero is the default
  2. people = []
  3.  
  4.  
  5. def elevator():     # elevator, appends a floor, removes a floor
  6.     result = 0
  7.     raw = raw_input('Up or Down: ')
  8.     if raw == 'up' or raw == 'Up' or raw == 'UP' or raw == 'uP':
  9.         floor.append(1)
  10.     elif raw == 'down' or raw == 'Down' or raw == 'DOWN':
  11.         floor.remove(1)
  12.     return result
  13.  
  14.  
  15. def get_off(person):    # adds person to list, based on user input
  16.     people.remove(person)
  17.  
  18.  
  19. def get_on(person):     # removes person to list, based on user input
  20.     people.append(person)
  21.  
  22.  
  23. def main():
  24.     try:
  25.         print '\n'
  26.         print 'You are on level %s.' % str(len(floor))      # Tells what floor you're on
  27.         print 'Here are your people', people                # Tells who is on your elevator
  28.         print '\n'
  29.  
  30.         if people:                                          # If there is something in the list, do this
  31.             who_off = raw_input('Who is getting off? ')
  32.             if who_off == '':                               # If no one gets off, ask who gets on
  33.                 who_on = raw_input('Who is getting on? ')
  34.                 if who_on == '':                            # If no one gets on, ask where to go, UP or DOWN
  35.                     elevator()
  36.                     main()
  37.                 print '\n'
  38.             else:                                           # If someone gets off, remove them from elevator
  39.                 get_off(who_off)
  40.                 who_on = raw_input('Who is getting on? ')   # Ask who gets on
  41.                 if who_on == '':                            # If no one gets on, ask where to go, UP or DOWN
  42.                     elevator()
  43.                     main()
  44.                 get_on(who_on)                              # If someone gets on, add them, then continue
  45.                 elevator()
  46.                 main()
  47.  
  48.         elif not people:                                    # If there is no one on the elevator
  49.             who_on = raw_input('Who is getting on? ')
  50.             if who_on == '':                                # If no one gets on, ask where to go, UP or DOWN
  51.                 elevator()
  52.                 main()
  53.             print '\n'
  54.             get_on(who_on)                                  # If someone gets on, add them to the elevator
  55.             elevator()
  56.             main()
  57.  
  58.     finally:
  59.         elevator()
  60.         main()
  61.  
  62. if __name__ == '__main__':                                  # Ensures that the main() function will be run
  63.  
  64.     # Gives user knowledge of what happens
  65.     print 'If no one gets on press ENTER.'
  66.     print 'If no one gets off press ENTER.'
  67.     print 'Else, enter in the name of who gets on.'
  68.  
  69.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement