Spaces:
Runtime error
Runtime error
File size: 761 Bytes
f5167da |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import csv
import random
import time
x_value = 0
total_1 = 1000
total_2 = 1000
fieldnames = ["x_value", "total_1", "total_2"]
with open('data.csv', 'w') as csv_file:
csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
csv_writer.writeheader()
while True:
with open('data.csv', 'a') as csv_file:
csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
info = {
"x_value": x_value,
"total_1": total_1,
"total_2": total_2
}
csv_writer.writerow(info)
print(x_value, total_1, total_2)
x_value += 1
total_1 = total_1 + random.randint(-5, 6)
total_2 = total_2 + random.randint(-5, 6)
time.sleep(1)
|