-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex26.py
More file actions
32 lines (31 loc) · 1.25 KB
/
Copy pathex26.py
File metadata and controls
32 lines (31 loc) · 1.25 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
# - Receba numeros inteiros do usuário e armazene-os em uma lista. Crie uma
# condição para o número 0 finalizar o processo de preenchimento. Após isso,
# imprima o maior valor da lista utilizando as funções sorted() e len(). Por fim,
# utilize reversed() para inverter a lista e obtenha, pelo índice, o valor
# intermediário da mesma.
# Obs.: Caso o número de valores da lista seja par, pegue a média dos dois
# valores centrais.
from biblioteca import libs
while True:
lista = []
while True:
lista.append(libs.lerInt('Digite um número: '))
op = str(input('Deseja adicionar mais?[S/N]: ')).strip().upper()[0]
if op not in 'SN':
print('ERRO! Digite "S" para sim e "N" para não')
continue
if op == 'S':
continue
elif op != 'S':
break
break
listaOrdenada = sorted(lista)
listaInvertida = list(reversed(listaOrdenada))
tamanho = len(lista)
print(f'O maior número digitado foi: {max(lista)}')
print(f'O menor número da lista foi: {min(lista)}')
if len(lista) % 2 == 1:
print(f'O valor intermediário é: {listaInvertida[tamanho//2]}')
else:
print(f'O valor intermediário é: '
f'{listaInvertida[tamanho // 2] + listaInvertida[(tamanho //2)- 1] / 2}')