I'm sorry for the confusing question but feel free to edit it.
My goal is to make an Attendance Checker using Python 3.x while associating it to an excel file.
I am a beginner in Python 3.x
Here is the code:
import openpyxl
wb_obj = openpyxl.load_workbook("A:\\Names.xlsx")
ws = wb_obj.active
def diff(first, second) -> type(None):
return list(result)
class_list_array = []
for i in ws.iter_rows(max_row=47):
for cell in i:
cell = cell.value
class_list_array.append(cell)
x = ""
end = 0
value = 0
while end < 47:
value += 1
up = value
x = "B" + str(up)
ws[x] = "PRESENT"
end += 1
#ws[count] = "PRESENT"
wb_obj.save(filename = "A:\\Names.xlsx")
print(class_list_array)
present_names = input("Who are present? \n")
present_names_array = present_names.split(", ")
present_names_array = [row.upper() for row in present_names_array]
print("PRESENT")
print(present_names_array)
print("")
a = set(present_names_array) - set(class_list_array)
b = set(class_list_array) - set(present_names_array)
result = a.union(b)
print("ABSENT/LATE")
print(diff(class_list_array, present_names_array))
#result = list(result)
#for rows in result:
# x = class_list_array.index(rows)
# cell = ws.cell(row = x, column = 2)
# cell.value = "ABSENT/LATE"
wb_obj.save(filename = "A:\\Names.xlsx")
The hashtags are me trying to figure out how do I get the index of a column in Excel.
What the code does is ask for the user's input. First, the present. Then, it compares the Present to the Class List Array; the result is the absent/late.
PROBLEM: I can't figure out how to add the label "ABSENT/LATE" next to the elements in the Absent/Late Array in Excel. For example, the array of Absent/Late is ["Bob", "Louise"] and Present is ["John"]
My desired result in an excel file is:
BOB | ABSENT/LATE
JOHN | PRESENT
Louise| ABSENT/LATE
MY "SOLUTION" but can't figure out how to do it: Get the index of the Absent/Late Array based on the Class List Array. For example, Class List Array ["Bob", "John", "Louise"]. Index is [0, 1, 2] In the Absent/List Array ["Bob, "Louise"]; their index is still attached so Bob is 0 and Louise is 2
Doing so, using the for loop I hashtagged, I can associate x = rows as rows = to the index of Bob and Louise at the original Class List Array: 0 & 2.
Again, this is my wild guess. Currently learning Python 3.x. Sorry for being a noob.