Ok basically I have 2 lines of data
name tribe id Air Water Earth Fire
Pema Xero X14C 24 54 34 43
Otaku Taru T111F 54 78 65 78
Currently, my code checks the column 'id' for errors according to certain conditions, but my code only reads the first row(Pema's row) and stops. I have no idea what is causing this, any help to fix this issue will be appreciated.
import csv
filePath ="data3.csv"
length="Length of Avatar ID is not 5 "
name_tribe= "Invalid first letter"
score_grade="Invalid last letter"
mid_integers="Invalid integers"
def isValidAvatarIDFormat():
with open(filePath) as csvfile:
reader = csv.DictReader(csvfile)
remarks=[]
for row in reader:
if(len(row['id'])!=5):
remarks.append(length)
if(row['tribe'][0] != row['id'][0]):
remarks.append (name_tribe)
avg_score= 0
user,tribe,id, *scores= row.values()
if all(score.isdigit() for score in scores):
average= sum([int(score) for score in scores])/4
if (average >=80):
avg_score="A"
elif (average >=70 and average <80):
avg_score="B"
elif (average >=60 and average <70):
avg_score="C"
elif (average >=50 and average <60):
avg_score="D"
elif (average >=40 and average <50):
avg_score="E"
else:
avg_score="F"
if(avg_score != row['id'][-1]):
remarks.append (score_grade)
if (row['id'][1].isdigit() and row['id'][2].isdigit() and row['id'][3].isdigit()):
continue
else:
remarks.append (mid_integers)
if (len(remarks) == 1):
print (remarks)
elif (len(remarks) >1):
for i in range(0, len(remarks)):
print(remarks[i])
del remarks
remarks =[]
print("{0:<10}{1:^18}{2:^15}".format("Avatar Name |","Avatar ID |","Comments"))
isValidAvatarIDFormat()