How do I gather information from each loop in a while loop python

Question:

I want to gather information from a while loop each time it loops over. For example, if you have a while loop that runs forever and encases an input asking for a number, and you add the numbers over time, how should I do that? Example:

while True:
  a = int(input("Enter a number "))
  a = a + a

Is there any way to do this? Thank you so much!

Asked By: Dev Scoop

||

Answers:

total = 0
while True:
  a = int(input("Enter a number "))
  total = total + a

  print(f"The total is {total}")
Answered By: Fredericka
total = 0
while True:
  a = int(input("Enter a number"))
  total = total + a

  print("The sum is ", total)
Answered By: 1ann0x
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.