Check if the door is open or closed | Python 3 implementation of doors open or closed ; Function to check whether ' n ' has even number of factors or not ; if ' n ' is a perfect square it has odd number of factors ; else ' n ' has even number of factors ; Function to find and print status of each door ; If even number of factors final status is closed ; else odd number of factors final status is open ; Driver program
import math NEW_LINE def hasEvenNumberOfFactors ( n ) : NEW_LINE INDENT root_n = math . sqrt ( n ) NEW_LINE if ( ( root_n * root_n ) == n ) : NEW_LINE INDENT return False NEW_LINE DEDENT return True NEW_LINE DEDENT def printStatusOfDoors ( n ) : NEW_LINE INDENT for i in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( hasEvenNumberOfFactors ( i ) == True ) : NEW_LINE INDENT print ( " closed " , end = " ▁ " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " open " , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT n = 5 NEW_LINE printStatusOfDoors ( n ) NEW_LINE