1

I want to make a summation of the collected data from a while loop because I want to calculate Youtube video duration to divide them into days. I want to make something which collects the final answer from each loop and makes a summation process of them. How can I do that?

My code is:

while True:
    def youtube_calculater(x):
        return x * 60

    a = youtube_calculater(float(input("enter minutes: ")))

    def sum_operation(y):
        return a + y

    b = sum_operation(float(input("enter seconds: ")))

    def final_operation(n):
        return n / 60

    s = final_operation(b)
    print(s)
mkrieger1
  • 19,194
  • 5
  • 54
  • 65

1 Answers1

0

You could store every calculated s inside a list (I named it s_list in the example) and then use sum() to calculate the sum of all the entries.

s_list = []

while True:
    def youtube_calculater(x):
        return x * 60

    a = youtube_calculater(float(input("enter minutes: ")))

    def sum_operation(y):
        return a + y

    b = sum_operation(float(input("enter seconds: ")))

    def final_operation(n):
        return n / 60

    s = final_operation(b)
    s_list.append(s)
    print(s)
    print(sum(s_list))

If you dont care about every entry in the list. You can just create a variable sum_s the same way and always add s to the sum using sum_s += s.

bitflip
  • 3,436
  • 1
  • 3
  • 22