-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path4listasfor.py
55 lines (46 loc) · 5.18 KB
/
4listasfor.py
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
#Ahora nos introduciremos a los bucles for
'''
Supongamos que quiero felicitar a todos los alumnos de mi clase,
mediante Python. Podria hacerlo de la siguiente manera:
'''
clase = ["Pedrito", "Marcial", "Elias"]
print("Felicidades ", clase[0])
print("Felicidades ", clase[1])
print("Felicidades ", clase[2])
print("-------------------------")
#Desde luego, eso funcionaria. Pero que pasa si tengo
#mil alumnos? Debo escribir un mensaje para cada uno separadamente?
#En Python no es necesario!
'''
Tenemos lo que se llama el bucle for
for |variable| in LISTA:
-------------------
| |
| |
| |
| Aqui van tus |
| instrucciones |
| |
| |
| |
-------------------
(Esto ya no es una instruccion)
'''
for nino in clase:
print("Felicidades ", nino)
print("He felicitado a todos mis alumnos")
print("--------------------------------------")
'''
Supongamos que somos meteorologos, y nuestra maquina registra
temperaturas a traves del dia, y queremos calcular el promedio
las temperaturas del dia. Para ello podemos usar un bucle for
Recordemos que el promedio de un conjunto de datos es
suma_de_los_datos/cantidad_de_datos
'''
temperaturas = [21.279218897713463, 27.899798723580957, 16.93683084472986, 16.536721502141457, 0.6083333223137344, 12.083541435037926, 9.724468013876068, 24.567669331532507, 19.02104639965216, -7.8488095920052885, 9.951923467269717, 6.46303074317035, -6.863959496496735, 22.885985988413715, 14.413191372762533, 0.4621033513182726, 28.97437095424206, 5.883359631147311, 5.178477667897672, 3.2558422970603673, 23.2942617944067, 18.69915108888215, 12.403393915125555, 11.61208716261817, 23.23817295510681, 0.4796112178871792, -2.9450279404622193, -2.494324796098988, 29.172449824204023, 23.073665977210844, -0.034104123643576845, -6.167852681905936, 17.45532543130397, 17.646000157928007, -6.041472108237544, 0.3239199969130069, 19.79801297522477, 30.99890310358169, 11.519802080209754, 22.158085482397112, 28.402279510241648, 19.764083324644403, 23.885672191634846, 10.157540699375726, 28.567520769248695, 20.346200863537376, 16.06105219126745, 16.063189070006093, -1.9077662915411442, 16.329645173710187, -7.739994212380365, 15.267574717397691, 23.166448183875723, 8.427903165887798, 16.249764089548023, 10.949356703823286, 7.886708444104052, 17.793555083789517, 31.853157006921215, -7.910369577826463, 26.93034346375847, 8.911144427899231, 10.005314068037212, 16.894862915420127, 4.249881891701214, 26.37066006966336, -7.982292281197891, 26.26760099613047, 22.720909300100082, 13.384824911584559, 19.513995522062146, 25.544510676187944, 16.618203719959293, 26.46693142630636, -3.4236733511310713, 8.543988388756755, 19.981022088730704, 12.642199029806827, 19.87088593456155, -1.5341764139027103, 3.4044640884486577, 22.327805040836182, 15.05247132326451, 17.903786758317228, 23.138319593969065, 21.247826568204438, 4.5335259093215825, 8.767899309740638, 13.653280602680445, 5.078317211653955, 5.507421255319802, 3.7412165133036823, -4.856781080840856, -0.36701692744456116, -1.284300457541081, 7.105642218159208, 22.83956248509603, 24.08597057443913, 17.251856837912648, -3.427698715993792, 25.848231681383016, -5.153056393723416, 29.62912673555996, 12.708326149739008, 2.8083169717753065, 5.724462489923516, 27.041813912602777, -7.965744355919513, -5.396811517111468, 10.665500477405942, -1.1830717526443935, 8.827569278769502, -7.431547020845512, 29.133539510066846, 15.503868124391921, 18.35419321139353, 13.014677368509593, 23.054031214327342, 23.47590500238237, 9.162179044023365, 11.3004355631808, -4.841871876151014, -7.01633470274767, 30.75858346386722, 10.3907806449551, 23.263148284609407, 29.83258778624795, -5.269115821932859, 31.343608017137974, -1.6646925971534876, 12.015163199489793, 0.06361551421704137, 28.2439770937954, 1.9297564992481742, 3.7226913068467016, 4.879038103862527, -2.039161903228053, 16.858893461258685, -2.064676266713643, 7.242755497021552, 20.88723711790327, -5.210620207057552, 21.551114186527258, -7.531202444884382, 12.07461548399748, 13.135389759564118, 21.58065868560996, 16.358303314344834, 17.93010672601576, 23.825549199391183, 16.215399494909388, 31.77949191493088, -6.018205876820126, -3.576203844304444, 4.751378104606417, 31.735947631182455, 5.050438885447283, 17.27747560660054, 23.13911562322506, 19.94094515964352, -0.6432360244949398, 10.995621624010202, 29.758516046833854, 4.347661942255437, 27.025552842733866, 18.578405223274206, 28.529668191133126, 7.177329947896888, 20.334711150361056, -5.4005661858694936, 8.940921330758343, -2.7929648861484258, 3.6592254234546595, 23.232162982757032, 10.686344216471484, -6.557090546688034, 8.476679093137555, 18.2773277390633, 13.509710998561497, 20.113730740528204, 27.806153758432337, 23.76287708675834, 18.679427257683717, 5.485075142085607, 2.5768277652948, -2.108076870424258, 14.707222442015661, 1.2513841084131472, 10.535400033695852, 27.411206598854605, 9.984931768074963, -0.8307688890404541, 5.25543864969938, 3.9549154180427393, 8.259667302706049, -7.687713997701701, 28.790182401083264, 11.2712738783794, -2.001791335780807, 2.4297200731163016]
suma = 0
cantidad_de_datos = len(temperaturas)
for temp in temperaturas:
suma = suma + temp
promedio = suma/cantidad_de_datos
print("El promedio de temperaturas del dia es: ", promedio)