# Rango simple. Python

May 19th, 2022 (edited)
747
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #!/usr/bin/env python
2.
3. # -*- coding: utf-8 -*-
4.
5. # Rango.py
6.
7.
8. m = list(range(10))
9.
10. print('El rango\n', m, '\n')
11.
12. Tm = sum(i for i in m)
13.
14. print('Suma Total del rango:', Tm, '\n')
15.
16. print('Promedio del rango', Tm/len(m), '\n')
17.
18. p = []
19. for i in range(len(m)):
20.     if 0 <= i < len(m):
21.         p.append((round(float(i/Tm), 3)))   #* Con formato --> p.append('{:.2%}'.format(i/Tm))
22. print('Porcentajes', p, '\n')
23.
24. r = {k: v for k, v in zip(m, p)}
25. print('Número : Porcentaje\n', r)
26.
27.
28. '''
29. Salida
30. ======
31.             El rango
32.             [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
33.
34.             Suma Total del rango: 45
35.
36.             Promedio del rango 4.5
37.
38.             Porcentajes
39.             [0.0, 0.022, 0.044, 0.067, 0.089, 0.111, 0.133, 0.156, 0.178, 0.2]
40.
41. #*   -->    ['0.00%', '2.22%', '4.44%', '6.67%', '8.89%', '11.11%', '13.33%', '15.56%', '17.78%', '20.00%']
42.
43.             Número : Porcentaje
44.             {0: 0.0, 1: 0.022, 2: 0.044, 3: 0.067, 4: 0.089, 5: 0.111, 6: 0.133, 7: 0.156, 8: 0.178, 9: 0.2}
45.
46. #*  -->     {0: '0.00%', 1: '2.22%', 2: '4.44%', 3: '6.67%', 4: '8.89%', 5: '11.11%', 6: '13.33%', 7: '15.56%', 8: '17.78%', 9: '20.00%'}
47. '''