From 62c83db2e8f2402bf3f2c5e26f264a333d552570 Mon Sep 17 00:00:00 2001 From: brunombpereira Date: Tue, 16 May 2023 18:56:08 +0100 Subject: [PATCH] [LABI] tema04: added csv_writer.py --- 1ano/2semestre/labi/tema04/datafiles/rand.csv | 10 ++++++++++ 1ano/2semestre/labi/tema04/src/csv_writer.py | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 1ano/2semestre/labi/tema04/datafiles/rand.csv create mode 100644 1ano/2semestre/labi/tema04/src/csv_writer.py diff --git a/1ano/2semestre/labi/tema04/datafiles/rand.csv b/1ano/2semestre/labi/tema04/datafiles/rand.csv new file mode 100644 index 0000000..9aaeb18 --- /dev/null +++ b/1ano/2semestre/labi/tema04/datafiles/rand.csv @@ -0,0 +1,10 @@ +time;value +1;41 +2;37 +3;3 +4;3 +5;37 +6;22 +7;91 +8;7 +9;25 diff --git a/1ano/2semestre/labi/tema04/src/csv_writer.py b/1ano/2semestre/labi/tema04/src/csv_writer.py new file mode 100644 index 0000000..12743d1 --- /dev/null +++ b/1ano/2semestre/labi/tema04/src/csv_writer.py @@ -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()