Code Monkey home page Code Monkey logo

elevatorcontrol's People

Contributors

caiomoura1994 avatar

elevatorcontrol's Issues

testando essa parada

#veja que massa
`
class Cnpj:
def init( self ):
"""
Class to interact with Cnpj brazilian numbers
"""
pass

def validate( self, cnpj ):
    """ 
    Method to validate brazilian cnpjs
    Tests:

    >>> print Cnpj().validate('61882613000194')
    True
    >>> print Cnpj().validate('61882613000195')
    False
    >>> print Cnpj().validate('53.612.734/0001-98')
    True
    >>> print Cnpj().validate('69.435.154/0001-02')
    True
    >>> print Cnpj().validate('69.435.154/0001-01')
    False
    """
    # defining some variables
    lista_validacao_um = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4 , 3, 2]
    lista_validacao_dois = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]

    # cleaning the cnpj
    cnpj = cnpj.replace( "-", "" )
    cnpj = cnpj.replace( ".", "" )
    cnpj = cnpj.replace( "/", "" )

    # finding out the digits
    verificadores = cnpj[-2:]

    # verifying the lenght of the cnpj
    if len( cnpj ) != 14:
        return False

    # calculating the first digit
    soma = 0
    id = 0
    for numero in cnpj:

        # to do not raise indexerrors
        try:
            lista_validacao_um[id]
        except:
            break

        soma += int( numero ) * int( lista_validacao_um[id] )
        id += 1

    soma = soma % 11
    if soma < 2:
        digito_um = 0
    else:
        digito_um = 11 - soma

    digito_um = str( digito_um ) # converting to string, for later comparison

    # calculating the second digit
    # suming the two lists
    soma = 0
    id = 0

    # suming the two lists
    for numero in cnpj:

        # to do not raise indexerrors
        try:
            lista_validacao_dois[id]
        except:
            break

        soma += int( numero ) * int( lista_validacao_dois[id] )
        id += 1

    # defining the digit
    soma = soma % 11
    if soma < 2:
        digito_dois = 0
    else:
        digito_dois = 11 - soma

    digito_dois = str( digito_dois )

    # returnig
    return bool( verificadores == digito_um + digito_dois )

def format( self, cnpj ):
    """
    Method to format cnpj numbers.
    Tests:

    >>> print Cnpj().format('53612734000198')
    53.612.734/0001-98
    """
    return "%s.%s.%s/%s-%s" % ( cnpj[0:2], cnpj[2:5], cnpj[5:8], cnpj[8:12], cnpj[12:14] )

print Cnpj().validate('33829177000154')

tests

import doctest; doctest.testmod()`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.