-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfor_e_arrays.py
More file actions
67 lines (48 loc) · 1.32 KB
/
Copy pathfor_e_arrays.py
File metadata and controls
67 lines (48 loc) · 1.32 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
# Testes básicos e simples - For e arrays
x = ['123', '456', '789']
valores = []
for val in x:
valores.append(int(val))
print(valores)
x = ['123', '456', '789']
valores = []
for val in range(0,len(x)):
valores.append(int(val))
print(valores)
# Não deu certo assim, pois não inseriu os valores de x como números no array valores
# creating an empty list
lst = []
# number of elemetns as input
n = int(input("Enter number of elements : "))
# iterating till the range
for i in range(0, n):
ele = int(input())
lst.append(ele) # adding the element
print(lst)
print()
print(lst)
""" x = ['123', '456', '789']
valores = []
for val in x:
valores.append(int(val))
print()
print('------')
print()
print ("Outro script simples que somará 2 números")
# creating an empty list
lst = []
# number of elemetns as input
n = int(input("Enter number of elements : "))
# iterating till the range
for i in range(0, n):
ele = int(input())
lst.append(ele) # adding the element
print(lst)
print ("A soma é dos elementos da lista é: ", sum(lst))
media = sum(lst) / len(lst)
print("Média: ", media)
mediana = sum(lst) / 2
print("Mediana: ", mediana)
# Para executar este script digite em um terminal Linux digite na pasta onde o arquivo foi salvo:
# sudo ./soma_de_2_numeros_digitados.sh
"""