Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- floor = [0] # keeps track of which floor you're on, zero is the default
- people = []
- def elevator(): # elevator, appends a floor, removes a floor
- result = 0
- raw = raw_input('Up or Down: ')
- if raw == 'up' or raw == 'Up' or raw == 'UP' or raw == 'uP':
- floor.append(1)
- elif raw == 'down' or raw == 'Down' or raw == 'DOWN':
- floor.remove(1)
- return result
- def get_off(person): # adds person to list, based on user input
- people.remove(person)
- def get_on(person): # removes person to list, based on user input
- people.append(person)
- def main():
- try:
- print '\n'
- print 'You are on level %s.' % str(len(floor)) # Tells what floor you're on
- print 'Here are your people', people # Tells who is on your elevator
- print '\n'
- if people: # If there is something in the list, do this
- who_off = raw_input('Who is getting off? ')
- if who_off == '': # If no one gets off, ask who gets on
- who_on = raw_input('Who is getting on? ')
- if who_on == '': # If no one gets on, ask where to go, UP or DOWN
- elevator()
- main()
- print '\n'
- else: # If someone gets off, remove them from elevator
- get_off(who_off)
- who_on = raw_input('Who is getting on? ') # Ask who gets on
- if who_on == '': # If no one gets on, ask where to go, UP or DOWN
- elevator()
- main()
- get_on(who_on) # If someone gets on, add them, then continue
- elevator()
- main()
- elif not people: # If there is no one on the elevator
- who_on = raw_input('Who is getting on? ')
- if who_on == '': # If no one gets on, ask where to go, UP or DOWN
- elevator()
- main()
- print '\n'
- get_on(who_on) # If someone gets on, add them to the elevator
- elevator()
- main()
- finally:
- elevator()
- main()
- if __name__ == '__main__': # Ensures that the main() function will be run
- # Gives user knowledge of what happens
- print 'If no one gets on press ENTER.'
- print 'If no one gets off press ENTER.'
- print 'Else, enter in the name of who gets on.'
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement