-
Notifications
You must be signed in to change notification settings - Fork 0
/
Checking.py
executable file
·65 lines (50 loc) · 1.53 KB
/
Checking.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
# By Le Chen
# chenle02@gmail.com / le.chen@auburn.edu
#
# -*- coding: utf-8 -*-
"""
codes.Checking
~~~~~~~~~~~~~~
DESCRIPTION
Use this script to check if there are matching date-of-birth (DOB) in the second column of the given CSV file.
:copyright: (c) 2022 by Le Chen (chenle02@gamil.com).
:license: CREATIVE COMMON LICENSE.
:created at Tue 07 Jun 2022 08:35:04 PM EDT
"""
import csv
import sys
def CheckMatchingDOBs(CSVFile):
"""TODO: Docstring for Check.
:CSVFile: String of the CSV filename.
:returns: Number of matching pairs.
"""
csvreader = csv.reader(open(CSVFile))
# header = []
# header = next(csvreader)
# print(header)
# Read all rows
rows = []
for row in csvreader:
rows.append(row)
Count = len(rows)
print(f"There are {Count-1} students in total.\n")
# Now find the matching DOBs
Found = 0
for i in range(Count):
for j in range(i+1, Count, 1):
# print(rows[i][1], rows[j][1], i, j)
if rows[i][1] == rows[j][1]:
Found += 1
print(f"Find matching birthday on {rows[i][1]} for Students {rows[i][0]} and {rows[j][0]}")
return(Found)
def main():
# Parse the input CSV filename.
if len(sys.argv) < 2:
CSVFile = "DOB.csv"
print("Checking the test CSV file: DOB_Test.csv.\n")
else:
CSVFile = sys.argv[1]
print(f"\nFound {CheckMatchingDOBs(CSVFile)} pairs of matching birthdays.")
if __name__ == "__main__":
main()