Python
Почему при выводе среднего avg захватывает только 3 числа вместо четырех в ранге(4),что нужно исправить?

код:

from random import uniform
days = input("Enter number of days: \n\n")
print("Generated prices:")
a, b, c = [], [], []
for i in range(4):
a.append("{:= .2f}".format(uniform(60, 70)))
b.append("{:= .2f}".format(uniform(60, 70)))
c.append("{:= .2f}".format(uniform(60, 70)))

n = []
for i in range(4):
n.append((a[i]) + b[i] + c[i])
num = n[0]
days = float(days)
my_list1 = a[i]
my_list2 = b[i]
my_list3 = c[i]
list1 = str(my_list1).strip('[]')
list2 = str(my_list2).strip('[]')
list3 = str(my_list3).strip('[]')
avg = ((float(list1)) + (float(list2)) + (float(list3)))/days
print("Exchange 1:", a)
print("Exchange 2:", b)
print("Exchange 3:", c)
print("Average price:", f'{avg:.5f}')

вывод:
Enter number of days:

4
Generated prices:
Exchange 1: [' 68.69', ' 60.10', ' 60.37', ' 65.34']
Exchange 2: [' 65.36', ' 64.22', ' 67.72', ' 69.51']
Exchange 3: [' 65.68', ' 60.87', ' 61.48', ' 67.10']
Average price: 50.48750

Вместо Average price: 50.48750 должно быть число среднее всех чисел в р-не 65-70
Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Copyright © 2024 SCHOLAR.TIPS - All rights reserved.