-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestCambioMonedas.py
More file actions
66 lines (53 loc) · 2.24 KB
/
testCambioMonedas.py
File metadata and controls
66 lines (53 loc) · 2.24 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
ImporteAPagar = float(input("Cuanto pagas?"))
importeCoste = float(input("Cuanto cuesta?"))
importeDevolucion = ImporteAPagar-importeCoste
# print(importe)
# importes de los billetes y monedas con su tipo en singular
tipos = (
(500, "billete"),
(200, "billete"),
(100, "billete"),
(50, "billete"),
(20, "billete"),
(10, "billete"),
(5, "billete"),
(2, "moneda"),
(1, "moneda")
)
centimos = (
(0.5, "moneda"),
(0.2, "moneda"),
(0.1, "moneda"),
(0.05, "moneda"),
(0.02, "moneda"),
(0.01, "moneda")
)
while importeDevolucion>0.4:
if importeDevolucion >= 1:
for tipo in tipos:
valor = tipo[0]
descripcion = tipo[1]
# funcion para mostrar la s del plural si es necesario
def s(valor, text): return valor > 1 and text+"s" or text
if importeDevolucion/valor > 1:
# la doble barra es para redonderar en la division, seria lo mismo que seprar los decimales
print(int(importeDevolucion / valor), s((importeDevolucion / valor), descripcion), valor)
# la doble barra es para redonderar en la division, seria lo mismo que seprar los decimales
#print((b / valor), s((importe / valor), descripcion), valor)
# la doble barra es para redonderar en la division, seria lo mismo que seprar los decimales
print((importeDevolucion // valor), s((importeDevolucion / valor), descripcion), valor)
# cogemos el resto de la division
importeDevolucion = importeDevolucion % valor
print(importeDevolucion)
else:
print("el importe restante es: ", importeDevolucion)
for centimo in centimos:
valor = centimo[0]
descripcion = centimo[1]
# funcion para mostrar la s del plural si es necesario
def s(valor, text): return valor > 1 and text+"s" or text
if importeDevolucion/valor > 1:
b = abs(importeDevolucion) - abs(int(importeDevolucion)) # Parte decimal
print((b / valor), s((b / valor), descripcion), valor)
# cogemos el resto de la division
importeDevolucion = b % valor