-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbiblioteca.py
More file actions
114 lines (97 loc) · 2.52 KB
/
biblioteca.py
File metadata and controls
114 lines (97 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Creo la clase Libro con sus atributos y sus métodos
class Libro:
def __init__(self):
self.titulo = ""
self.autor = ""
self.isbn = ""
self.disponible = True
def agregar(self, titulo, autor, isbn):
self.titulo = titulo
self.autor = autor
self.isbn = isbn
def prestar(self):
if self.disponible:
self.disponible = False
print("Libro prestado con éxito.")
else:
print("Este libro ya está prestado.")
def devolver(self):
if not self.disponible:
self.disponible = True
print("Libro devuelto con éxito.")
else:
print("Libro ya disponible")
def mostrar(self):
disponibilidad = "Sí" if self.disponible else "No"
print(f"- {self.titulo} ({self.autor}) - ISBN: {self.isbn} - Disponible: {disponibilidad}")
def buscar(self, isbn):
if self.isbn == isbn:
self.mostrar()
return True
return False
# Creación de una lista donde se añadirán los libros agregados
libros = []
# Bucle para que el usuario interactue con el programa por menú
while True:
print("Bienvenido al Sistema de Gestión de Biblioteca\n")
print("1.Agregar libro")
print("2.Prestar libro")
print("3.Devolver libro")
print("4.Mostrar libros")
print("5.Buscar")
print("6.Salir\n")
opcion = int(input("Elija una opción: "))
#Agregar libro
if opcion == 1:
titulo = input("Título: ")
autor = input("Autor: ")
isbn = input("ISBN: ")
nuevo_libro = Libro()
nuevo_libro.agregar(titulo, autor, isbn)
libros.append(nuevo_libro)
print("Libro agregado con éxito.")
#Prestar libro
elif opcion == 2:
isbn = input("Ingresa el ISBN: ")
libro_encontrado = False
for libro in libros:
if libro.isbn:
libro.prestar()
libro_encontrado = True
break
if not libro_encontrado:
print("Libro no encontrado.")
#Devolver libro
elif opcion == 3:
isbn = input("Ingresa el ISBN: ")
libro_encontrado = False
for libro in libros:
if libro.isbn:
libro.devolver()
libro_encontrado = True
break
if not libro_encontrado:
print("Libro no encontrado.")
#Mostrar libros
elif opcion == 4:
if not libros:
print("No hay libros en la biblioteca.")
else:
for libro in libros:
libro.mostrar();
#Buscar libros
elif opcion == 5:
isbn = input("Ingresa el ISBN: ")
libro_encontrado = False
for libro in libros:
if libro.buscar(isbn):
libro_encontrado = True
break
if not libro_encontrado:
print("Libro no encontrado.")
#Salir del programa
elif opcion == 6:
break
#En caso de que el usuario ingrese una opción errónea
else:
print("Opción inválida.")