Calculating the Python Variable for in

Asked 2 years ago, Updated 2 years ago, 20 views

The value of the variable a contains the value [1, 2, 3, 4, 5], which is divided by adding the value from the previous to the third. I would like to display the so-called average value (b), but it doesn't work.

 if__name__=="_main__":

a = [1, 2, 3, 4, 5]
for i in range (len(a)) :
    a.append(a[i]+a[i]/3)
x = a.range(0,len(dates[0]))  

print(b)

python

2022-09-30 15:45

1 Answers

How about this?

 if__name__=="_main__":
    a = [1, 2, 3, 4, 5]
    target=a[:3]#=>[1,2,3]
    s=sum(target)
    l=len(target)
    b=s/l

    print(b)


2022-09-30 15:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.