Advertisement
arcanosam

Jail Break Quiz in Python

Aug 15th, 2012
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """ this code refer to this article: http://www.codeproject.com/Articles/436455/Jail-Break-Quiz
  3.  
  4. Points of Interest
  5. - just show a Python perspective, and how improve Legibility;  
  6. """
  7.  
  8. MAX = 101;    
  9.  
  10. def print_doors(door_is_open):
  11.  
  12.     output = ''
  13.  
  14.     for value in door_is_open:
  15.         if(value):
  16.             output +='o'
  17.         else:
  18.             output +='c'
  19.  
  20.     print '%s - %s open doors' % (output,output.count('o'))
  21.    
  22. if __name__ == "__main__":
  23.  
  24.     array = range(1,101)
  25.    
  26.     door_is_open = [False for door in array]
  27.  
  28.     for i in array:
  29.         for j in range(i,101,i):
  30.             door_is_open[j-1] = not door_is_open[j-1]
  31.    
  32.         print_doors(door_is_open)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement