コード例 #1
0
ファイル: Encrypter.py プロジェクト: Daglur/CodeBreaker
 def __init__( self, generateRandomCode=False ):
     self.attempts = 0
     if generateRandomCode:
         self.code = randomCode()
         print 'A random five digit code has been selected'
         return
     rawCode = raw_input("Please enter a five digit code to encrypt." + \
         "\nAnything else will cause a random number to be generated: ")
     if len( rawCode ) is not codeLength:
         self.code = randomCode()
     else:
         for i in range( 0, codeLength ):
             if not myIsDigit( rawCode[ i ] ):
                 code = randomCode() 
                 break
         self.code = map( int, rawCode )
     print 'Your code is:',
     for i in range( 0, codeLength ):
         print self.code[i],
     print
コード例 #2
0
ファイル: Mastermind.py プロジェクト: Daglur/CodeBreaker
def getGuess():
    rawGuess = raw_input( "Please enter a five digit code to guess:" )
    while len( rawGuess ) is not codeLength:
        rawGuess = raw_input( "Invalid, Please enter a five digit code:" )
    else:
        for i in range( 0, codeLength ):
            if not myIsDigit( rawGuess[ i ] ):
                guess = randomCode() 
                break
        guess = map( int, rawGuess )
    return guess