To resolve this issue we can use the following script:
def velocidade_media(ve, ac, te):
velocidades_kmh = list()
for v, a, t in zip(ve, ac, te):
velo = (v + (a * t))
velocidades_kmh.append(velo)
menor_kmh = min(velocidades_kmh)
menor_ms = (menor_kmh * 3.6)
return menor_kmh, menor_ms
n = int(input('Quantos veículos serão estudados? '))
vel = list()
ace = list()
tem = list()
for c in range(1, n + 1):
vel.append(float(input(f'Digite a velocidade inicial do {c}º carro: ')))
ace.append(float(input(f'Digite a aceleração do {c}º carro: ')))
tem.append(float(input(f'Digite o temp de percurso do {c}º carro, em horas: ')))
menor_velo_km, menor_velo_ms = velocidade_media(vel, ace, tem)
print(f'\033[32mA menor velocidade em "Km/h" é: {menor_velo_km:.2f} Km/h')
print(f'A menor velocidade em "m/s" é: {menor_velo_ms:.2f} m/s')
Note that when we execute this script, we must inform the amount of vehicles that will participate in the study (analysis). Then, we must insert velocidade inicial (Km/h), aceleração (km/h 2) and the tempo en route (h).
From that time the captured values will be stored in the lists vel, ace and tem respectively lists of speeds, accelerations and times.
Later these lists are sent as parameters to the function velocidade_media. Once there, these lists will be simultaneously traversed by the loop of repetition for with the help of function zip, calculating for each nth interaction the value of its velocidade final in Km/h and then stored their values in the list velocidades_kmh. Subsequently the lowest speed is calculated in Km/h (less_kmh) and then this speed is converted to m/s (menor_ms).
After that the function velocidade_media return two values, which are respectively, menor_kmh and menor_ms.
Soon after the print functions will show the values of the lowest speed in Km/h (less_kmh) and lowest speed in m/s (less_ms).
Its function
velkmhshould not return something? Moreover, what is 3.6?– Pablo Almeida
3.6 is the constant for turning m/s into km/h, I forgot to mention this. I tried to apply the function to each set of given values, but I think I did it wrong. I imagined that the calculated values would be stored by the program so that they could be used later.
– Guilherme Santana De Souza
I’ll edit the question.
– Guilherme Santana De Souza
I suggest you change
V = ....forreturn ..... Also, if the speed in Km/h is not useful, make your function return the speed already in m/s (ie, move the* 3.6into the function). I believe this will help.– Pablo Almeida
I made some changes to the code. Now I just need the program to analyze each value, choose the smallest and print it out. I will return with the answer if I find.
– Guilherme Santana De Souza