uaveiro-leci/1ano/1semestre/fp/aula05/ex02.py

56 lines
1.0 KiB
Python
Raw Permalink Normal View History

2022-10-20 21:22:14 +00:00
def main():
floatList = inputFloatList()
print(floatList)
print()
2023-01-30 16:48:43 +00:00
2022-10-20 21:22:14 +00:00
# Tem de dar print a '4'
print(countLower([1321, 143, 1432, 512, 43, 153, 143613], 1000))
print()
2023-01-30 16:48:43 +00:00
2022-10-20 21:22:14 +00:00
# Tem de dar print a 43, 143613
print(minmax([1321, 143, 1432, 512, 43, 153, 143613]))
print()
2023-01-30 16:48:43 +00:00
2022-10-20 21:22:14 +00:00
#
mix()
2023-01-30 16:48:43 +00:00
def inputFloatList(inputMsg='>>> '):
2022-10-20 21:22:14 +00:00
returnList = []
while True:
inpt = input(inputMsg)
2023-01-30 16:48:43 +00:00
if inpt == '':
return returnList
2022-10-20 21:22:14 +00:00
try:
returnList.append(float(inpt))
2023-01-30 16:48:43 +00:00
except ValueError:
2022-10-20 21:22:14 +00:00
continue
2023-01-30 16:48:43 +00:00
2022-10-20 21:22:14 +00:00
def countLower(lst, v):
2023-01-30 16:48:43 +00:00
return len([lst[i] for i in range(len(lst)) if lst[i] < v])
2022-10-20 21:22:14 +00:00
def minmax(lst):
2023-01-30 16:48:43 +00:00
mx = lst[0]
mn = lst[0]
2022-10-20 21:22:14 +00:00
for n in lst:
if n > mx:
mx = n
if n < mn:
mn = n
2023-01-30 16:48:43 +00:00
return mn, mx
2022-10-20 21:22:14 +00:00
# Alinea d)
def mix():
lst = inputFloatList()
mn_mx = minmax(lst)
med = (mn_mx[0] + mn_mx[1]) / 2
count = countLower(lst, med)
print(count)
2023-01-30 16:48:43 +00:00
2022-10-20 21:22:14 +00:00
if __name__ == "__main__":
2023-01-30 16:48:43 +00:00
main()