Created
February 15, 2014 15:11
-
-
Save digenaldo/9020503 to your computer and use it in GitHub Desktop.
Projeto Biblioteca - Introdução a Programação - Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#funções projeto gerenciador de bibliotecas | |
#autores: digenaldo neto, caio cezar, walber luis | |
def retornaLogin(): | |
""" Verifica o arquivo e retorna todo o arquivo do funcionario em lista """ | |
lista2 = [] | |
arquivo = open('dadosFuncionarios.txt','r') | |
lista = arquivo.readlines() | |
for i in range(len(lista)): | |
string = lista[i] | |
string = string.replace('\n','') | |
lista2.append(string) | |
return lista2 | |
def retornaAluno(): | |
""" Verifica o arquivo e retorna todo o arquivo dos alunos em lista """ | |
lista2 = [] | |
arquivo = open('dadosAlunos.txt','r') | |
lista = arquivo.readlines() | |
for i in range(len(lista)): | |
string = lista[i] | |
string = string.replace('\n','') | |
lista2.append(string) | |
return lista2 | |
def retornaEmprestimo(): | |
""" Verifica o arquivo e retorna todo o arquivo dos alunos em lista """ | |
lista2 = [] | |
arquivo = open('emprestimo.txt','r') | |
lista = arquivo.readlines() | |
for i in range(len(lista)): | |
string = lista[i] | |
string = string.replace('\n','') | |
lista2.append(string) | |
return lista2 | |
def retornaLivro(): | |
""" Verifica e retorna todo o conteúdo do livro selecionado em lista """ | |
lista2 = [] | |
arquivo = open('dadosLivros.txt','r') | |
lista = arquivo.readlines() | |
for i in range(len(lista)): | |
string = lista[i] | |
string = string.replace('\n','') | |
lista2.append(string) | |
return lista2 | |
def listaAcervo(): | |
""" Retorna os todos os titulos dos livros cadastrados""" | |
lista2 = [] | |
lista = retornaLivro() | |
for i in range(len(lista)): | |
if(i % 3 == 0): | |
print(lista[i]) | |
def verificaLogin(cadFunc, loginFunc, senhaFunc): | |
""" Verifica se o login e a senha, estao corretas com o funcionario """ | |
for i in range(len(cadFunc)): | |
if(loginFunc in cadFunc and senhaFunc in cadFunc): | |
print('Acesso permitido, bem vindo ao sistema...') | |
print('-' * 40) | |
dadosErrados = 0 | |
liberado = True | |
break | |
else: | |
dadosErrados = 1 | |
continue | |
if(dadosErrados != 0): | |
while(dadosErrados != 0): | |
print('Login ou Senha Inválidos. Tente novamente') | |
print() | |
loginFunc = input('Nome: ') | |
senhaFunc = input('CPF ou Matricula: ') | |
print() | |
for i in range(len(cadFunc)): | |
if(loginFunc in cadFunc and senhaFunc in cadFunc): | |
print('Acesso permitido, bem vindo ao sistema...') | |
print('-' * 40) | |
dadosErrados = 0 | |
liberado = True | |
break | |
else: | |
dadosErrados = 1 | |
continue | |
return liberado | |
def verificaOpcao(opcao): | |
""" Função para identificar a opção do usuario """ | |
while(opcao != '1' and opcao != '2' and opcao != '3' and opcao != '4'): | |
print() | |
print('Opção errada, digite novamente!') | |
print() | |
opcao = input("Informe Novamente: ") | |
return opcao | |
def verificaLetra(nome): | |
""" Função para identificar caracteres não letras """ | |
caracter = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] | |
juntar = nome.replace(' ','') | |
lista = list(juntar) | |
tam = len(lista) | |
tamCaracter = len(caracter) | |
while 1: | |
for i in range(tam): | |
if(tam <= tamCaracter): | |
if(not(lista[i] in caracter)): | |
erro = 1 | |
else: | |
erro = 0 | |
return nome | |
if(tam > tamCaracter): | |
if(not(caracter[i] in lista)): | |
erro = 1 | |
else: | |
erro = 0 | |
if(erro > 0): | |
print() | |
print('Erro... Digite apenas letras...') | |
nome = input('Digite Novamente: ') | |
juntar = nome.replace(' ','') | |
lista = list(juntar) | |
tam = len(lista) | |
if(erro == 0): | |
break | |
def verificaIdade(): | |
""" Verifica a idade do usuario """ | |
while 1: | |
try: | |
idade = int(input('Informe a idade: ')) | |
idade = menorQueZero(idade) | |
break | |
except: | |
print() | |
print('Digite apenas números.') | |
print() | |
return idade | |
def menorQueZero(num): | |
""" Identifica se um numero é maior que zero""" | |
while 1: | |
while(num <= 0): | |
print() | |
print('Digite apenas números e maiores que zero.') | |
try: | |
print() | |
num = int(input('Informe novamente: ')) | |
except: | |
print() | |
else: | |
break | |
return num | |
def cadastrarAlunos(): | |
""" Função para o cadastramento dos alunos """ | |
arquivo = open('dadosAlunos.txt','a') | |
lista = [] | |
print() | |
nome = str.lower(input('Informe o nome: ')) | |
lista.append(verificaLetra(nome)) | |
lista.append(verificaIdade()) | |
lista.append(input('Informe o RG: ')) | |
lista.append(input('Informe o CPF: ')) | |
lista.append(input('Informe a matricula: ')) | |
for i in range(len(lista)): | |
arquivo.write('%s\n' %lista[i]) | |
arquivo.close() | |
retornarLista = open('dadosAlunos.txt','r') | |
lista2 = retornarLista.readlines() | |
retornarLista.close() | |
return lista2 | |
def cadastrarFuncionarios(): | |
""" Função para o cadastramento dos funcionarios """ | |
arquivo = open('dadosFuncionarios.txt','a') | |
lista = [] | |
print() | |
nome = str.lower(input('Informe o nome: ')) | |
lista.append(verificaLetra(nome)) | |
lista.append(input('Informe a idade: ')) | |
lista.append(input('Informe o RG: ')) | |
lista.append(input('Informe o CPF: ')) | |
lista.append(input('Informe a matricula: ')) | |
for i in range(len(lista)): | |
arquivo.write('%s\n' %lista[i]) | |
arquivo.close() | |
retornarLista = open('dadosFuncionarios.txt','r') | |
lista2 = retornarLista.readlines() | |
retornarLista.close() | |
return lista2 | |
def cadastrarLivros(): | |
""" Função para o cadastramento de livros """ | |
arquivo = open('dadosLivros.txt','a') | |
lista = [] | |
print() | |
lista.append(input('Informe o titúlo do livro: ')) | |
lista.append(input('Informe a editora: ')) | |
lista.append(input('Informe o ano: ')) | |
for i in range(len(lista)): | |
arquivo.write('%s\n' %lista[i]) | |
arquivo.close() | |
retornarLista = open('dadosLivros.txt','r') | |
lista2 = retornarLista.readlines() | |
retornarLista.close() | |
return lista2 | |
def emprestimo(): | |
""" Faz o emprestimo de livro a um aluno cadstrado """ | |
lista2 = ['',''] | |
listaAluno = retornaAluno() | |
listaLivro = retornaLivro() | |
while 1: | |
nomeAluno = input('Informe o nome do aluno: ') | |
tituloLivro = input('Informe o titulo do livro: ') | |
lista2[0] = nomeAluno | |
lista2[1] = tituloLivro | |
if not(lista2[0] in listaAluno and lista2[1] in listaLivro): | |
print() | |
print('Aluno inexistente ou livro já emprestado/não existe.') | |
print() | |
sair = str.lower(input('Deseja fazer o empréstimo novamente ? Sim ou Nao: ')) | |
print() | |
if(sair == 'sim'): | |
continue | |
else: | |
break | |
else: | |
arquivo = open('emprestimo.txt','a') | |
arqLivro = open('dadosLivros.txt','w') | |
for i in range(len(lista2)): | |
arquivo.write('%s\n' %lista2[i]) | |
for i in range(len(listaLivro)): | |
if(lista2[1] == listaLivro[i]): | |
string = listaLivro[i] | |
listaLivro[i] = string + ' -> (Livro não disponível para empréstimo)' | |
arqLivro.write('%s\n' %listaLivro[i]) | |
arqLivro.close() | |
arquivo.close() | |
print() | |
sair = str.lower(input('Deseja fazer outro empréstimo ? Sim ou Nao: ')) | |
print() | |
if(sair == 'sim'): | |
continue | |
else: | |
break | |
print('Empréstimo finalizado com sucesso.') | |
def devolucao(): | |
""" Faz a devolução de livros de alunos que solicitaram emprestimos """ | |
arquivo = open('emprestimo.txt','a') | |
lista2 = ['',''] | |
listaEmprestimo = retornaEmprestimo() | |
listaLivro = retornaLivro() | |
while 1: | |
nomeAluno = input('Informe o nome do aluno: ') | |
tituloLivro = input('Informe o titulo do livro: ') | |
lista2[0] = nomeAluno | |
lista2[1] = tituloLivro | |
if not(lista2[0] in listaEmprestimo and lista2[1] in listaEmprestimo): | |
print() | |
print('Aluno inexistente ou livro já devolvido/não existe.') | |
print() | |
sair = str.lower(input('Deseja fazer outra devolução ? Sim ou Nao: ')) | |
print() | |
if(sair == 'sim'): | |
continue | |
else: | |
break | |
else: | |
arquiEmprestimo = open('emprestimo.txt','w') | |
arqLivro = open('dadosLivros.txt','w') | |
for i in range(len(listaLivro)): | |
if(lista2[1] + ' -> (Livro não disponível para empréstimo)' == listaLivro[i]): | |
listaLivro[i] = lista2[1] | |
arqLivro.write('%s\n' %listaLivro[i]) | |
for i in range(len(listaEmprestimo)): | |
if(lista2[0] == listaEmprestimo[i]): | |
listaEmprestimo[i] = '' | |
if(lista2[1] == listaEmprestimo[i]): | |
listaEmprestimo[i] = '' | |
arquiEmprestimo.write('%s\n' %listaEmprestimo[i]) | |
arqLivro.close() | |
arquiEmprestimo.close() | |
print() | |
sair = str.lower(input('Deseja fazer outra devolução ? Sim ou Nao: ')) | |
print() | |
if(sair == 'sim'): | |
continue | |
else: | |
break | |
print('Devolução finalizada com sucesso.') | |
def relatorioAluno(): | |
listaAluno = retornaAluno() | |
listaRelatorio = ['Nome: ','Idade: ','RG: ','CPF: ','Matrícula: '] | |
for i in range(len(listaAluno)): | |
print(listaRelatorio[i],listaAluno[i]) | |
listaRelatorio.append(listaRelatorio[i]) | |
if((i + 1) % 5 == 0): | |
print() | |
def relatorioFuncionario(): | |
listaFunc = retornaLogin() | |
listaRelatorio = ['Nome: ','Idade: ','RG: ','CPF: ','Matrícula: '] | |
for i in range(len(listaFunc)): | |
print(listaRelatorio[i],listaFunc[i]) | |
listaRelatorio.append(listaRelatorio[i]) | |
if((i + 1) % 5 == 0): | |
print() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Gerenciamento de Biblioteca | |
#autor: digenaldo neto, caio cezar, walber luis | |
#importação das bibliotecas | |
import defProjeto | |
#tela de titulo do sistema | |
while 1: | |
print() | |
print('-' * 40) #cria 40 '-' para dividir o titulo | |
print('Bem vindo ao sistema BiBli'.center(40)) #centraliza o texto de acordo com a qtd de espaçamentos | |
print('-' * 40) | |
print('Tela de login'.center(40)) | |
print() | |
#fim da tela de titulo do sistema | |
#tela de login para acessar o sistema | |
loginFunc = input('Nome: ') | |
senhaFunc = input('CPF ou Matricula: ') | |
print() | |
liberado = defProjeto.verificaLogin(defProjeto.retornaLogin(), loginFunc, senhaFunc) #função que verifica se o login e senha estão corretos, e recebe valor de True ou False | |
print() | |
#fim da tela de login | |
#se o login for aceito a função retorna verdadeiro e entra no menu do sistema | |
if (liberado == True): | |
while 1: | |
print() | |
print('Menu do Sistema'.center(40)) | |
print('Escolha o número referente a opção desejada'.center(40)) | |
print() | |
opcao = input("1 - Cadastro 2 - Movimentações 3 - Relatórios 4 - Finalizar: ") | |
opcao = defProjeto.verificaOpcao(opcao) #usando a função verificaOpcao, caso o usuário digite alguma opção que não corresponda com a solicitada | |
if(opcao == '1'): | |
print() | |
opcaoCad = input('1 - Cadastrar Aluno 2 - Cadastrar Funcionário 3 - Cadastrar Livro 4 - Retornar ao Menu Anterior: ') | |
opcao = defProjeto.verificaOpcao(opcaoCad) #usando a função verificaOpcao | |
if(opcao == '1'): | |
print() | |
print('...::: Cadastro de Alunos :::...') | |
cadMaisUm = 'sim' | |
while(cadMaisUm != 'nao'): #inicia o loop para solicitar ao usuário se deseja cadastrar mais um | |
defProjeto.cadastrarAlunos() #executa a função cadastrar alunos | |
cadMaisUm = str.lower(input('Deseja cadastrar mais um aluno ? Sim ou Nao: ')) | |
#fim do loop | |
elif(opcao == '2'): | |
print() | |
print('...::: Cadastro de Funcionários :::...') | |
cadMaisUm = 'sim' | |
while(cadMaisUm != 'nao'): #inicia o loop para solicitar ao usuário se deseja cadastrar mais um | |
defProjeto.cadastrarFuncionarios() #executa a função cadastrar funcionarios | |
cadMaisUm = str.lower(input('Deseja cadastrar mais um funcionário ? Sim ou Nao: ')) | |
#fim do loop | |
elif(opcao == '3'): | |
print() | |
print('...::: Cadastro de Livros :::...') | |
cadMaisUm = 'sim' | |
while(cadMaisUm != 'nao'): #inicia o loop para solicitar ao usuário se deseja cadastrar mais um | |
defProjeto.cadastrarLivros() #recebe a função cadastrarLivro | |
cadMaisUm = str.lower(input('Deseja cadastrar mais um livro ? Sim ou Nao: ')) | |
#fim do loop | |
elif(opcao == '4'): | |
continue | |
elif(opcao == '2'): | |
while 1: | |
print() | |
opcaoCad = input('1 - Consultar Acervo 2 - Empréstimo 3 - Devolução 4 - Retornar ao Menu Anterior: ') | |
opcao = defProjeto.verificaOpcao(opcaoCad) #utiliza a função verificaOpção para identificar algum numero invalido | |
if(opcao == '1'): | |
print('-' * 40) | |
print('...::: Livros disponíveis :::...') | |
print() | |
defProjeto.listaAcervo() #recebe a função listaAcervo, que acessa o arquivo dadosLivros e retorna o nome dos livros disponiveis | |
print() | |
print('-' * 40) | |
continue | |
elif(opcao == '2'): | |
print('-' * 40) | |
print('...::: Empréstimo de Livros :::...') | |
print() | |
defProjeto.emprestimo() #recebe a função emprestimo onde irá acessar o arquivo aluno e livro e fazer a transação | |
print() | |
print('-' * 40) | |
elif(opcao == '3'): | |
print('-' * 40) | |
print('...::: Devolução de Livros :::...') | |
print() | |
defProjeto.devolucao() #recebe a função devolução onde irá acessar o arquivo aluno e livro e fazer a transação | |
print() | |
print('-' * 40) | |
elif(opcao == '4'): | |
break | |
elif(opcao == '3'): | |
while 1: | |
print() | |
opcaoRel = input('1 - Relatório Alunos Cadastrados 2 - Relatório Funcionários Cadastrados: ') | |
opcao = defProjeto.verificaOpcao(opcaoRel) | |
if(opcao == '1'): | |
print('-' * 40) | |
print('...::: Relatório Alunos :::...') | |
print() | |
defProjeto.relatorioAluno() #executa a função relatorio aluno | |
print() | |
print('-' * 40) | |
print() | |
sair = str.lower(input('Deseja voltar ao menu anterior: Sim ou Nao: ')) | |
if(sair == 'sim'): | |
continue | |
else: | |
break | |
elif(opcao == '2'): | |
print('-' * 40) | |
print('...::: Relatório Funcionários :::...') | |
print() | |
defProjeto.relatorioFuncionario() #executa a função realatorio funcionario | |
print() | |
print('-' * 40) | |
print() | |
sair = str.lower(input('Deseja voltar ao menu anterior: Sim ou Nao: ')) | |
if(sair == 'sim'): | |
continue | |
else: | |
break | |
elif(opcao == '4'): | |
break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment