-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Expand file tree
/
Copy pathlabs-Carla.py
More file actions
119 lines (94 loc) · 3.7 KB
/
Copy pathlabs-Carla.py
File metadata and controls
119 lines (94 loc) · 3.7 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
113
114
115
116
117
118
import os
"""Ejercicio"""
file_name = "labs-Carla.txt"
with open(file_name,"w") as file:
file.write("Carla\n")
file.write("25\n")
file.write("Python\n")
with open(file_name, "r") as file:
print(file.read())
os.remove(file_name)
"""Extra"""
def gestion_ventas():
ventas_file = "ventas.txt"
ventas = []
while True:
print("1. Añadir producto")
print("2. Consultar producto")
print("3. Actualizar productos")
print("4. Eliminar productos")
print("5. Mostrar productos")
print("6. Calcular venta total")
print("7. Calcular venta por producto")
print("8. Salir")
option = input("¿Qué desea realizar?\n")
match option:
case "1":
nombre_producto = input("Nombre producto:\n")
cantidad_vendida = int(input("Cantidad: "))
precio = int(input("Precio: "))
nueva_venta = {
"nombre_producto": nombre_producto,
"cantidad_vendida": cantidad_vendida,
"precio": precio
}
with open(ventas_file, "a") as file:
file.write(
f"{nombre_producto},{cantidad_vendida},{precio}\n"
)
ventas.append(nueva_venta)
case "2":
name = input("Nombre del producto: ")
with open(ventas_file, "r") as file:
for line in file.readlines():
if line.split(",")[0] == name:
print(line)
break
case "3":
nombre_producto = input("Nombre producto:\n")
cantidad_vendida = int(input("Cantidad: "))
precio = int(input("Precio: "))
with open(ventas_file, "r") as file:
lines = file.readlines()
with open(ventas_file, "w") as file:
for line in lines:
if line.split(",")[0] == nombre_producto:
file.write(f"{nombre_producto},{cantidad_vendida},{precio}\n")
else:
file.write(line)
case "4":
name = input("Nombre del producto: ")
with open(ventas_file, "r") as file:
lines = file.readlines()
with open(ventas_file, "w") as file:
for line in lines:
if line.split(",")[0] != name:
file.write(line)
case "5":
with open(ventas_file, "r") as file:
print(file.read())
case "6":
total = 0
with open(ventas_file, "r") as file:
for line in file.readlines():
components = line.split(",")
quantity = int(components[1])
price = float(components[2])
total += quantity * price
print(total)
case "7":
name = input("Nombre: ")
total = 0
with open(ventas_file, "r") as file:
for line in file.readlines():
components = line.split(",")
if components[0] == name:
quantity = int(components[1])
price = float(components[2])
total += quantity * price
print(total)
break
case "8":
os.remove(ventas_file)
break
gestion_ventas()