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!
Answers:
total = 0
while True:
a = int(input("Enter a number "))
total = total + a
print(f"The total is {total}")
total = 0
while True:
a = int(input("Enter a number"))
total = total + a
print("The sum is ", total)
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!
total = 0
while True:
a = int(input("Enter a number "))
total = total + a
print(f"The total is {total}")
total = 0
while True:
a = int(input("Enter a number"))
total = total + a
print("The sum is ", total)