[LABI] tema04: added csv_writer.py

This commit is contained in:
brunombpereira 2023-05-16 18:56:08 +01:00
parent 1cd588c313
commit 78f4c52302
Signed by untrusted user who does not match committer: TiagoRG
GPG Key ID: DFCD48E3F420DB42
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,10 @@
time;value
1;41
2;37
3;3
4;3
5;37
6;22
7;91
8;7
9;25
1 time value
2 1 41
3 2 37
4 3 3
5 4 3
6 5 37
7 6 22
8 7 91
9 8 7
10 9 25

View File

@ -0,0 +1,16 @@
import csv
import random
def main():
fout = open("rand.csv", "w", newline='')
writer = csv.DictWriter(fout, fieldnames=["time", "value"], delimiter=';')
writer.writeheader()
for i in range(1, 10):
writer.writerow({"time": i, "value": random.randint(1, 100)})
fout.close()
main()