2 years ago

#44830

test-img

Jeon Lei

How to connect a variable to variable from a 'for' loop?

I really don't know to how to connect the variable to the variable from a 'for' loop. This code of mine should calculate the accumulated time then calculate it again to have the average wage. The calculator would accumulate the time from a certain user to the list, then calculate the time to have the wage. It seems that it doesn't apply well to the list, especially knowing that the time came from a 'list'. It also doesn't really apply 'split' to the elements from the list.

import time 
from datetime import datetime

wage_per_hour=float(150)
employee=["ANNA","MARISSA"]
pin=["12345","56789"]
full_name=["Anna Marie","Marissa Gee"]

employee1_data_login_time = [];
employee1_data_login_date = [];
employee1_data_logout_time = [];
employee1_data_logout_date = [];
employee2_data_login_time = [];
employee2_data_login_date = [];
employee2_data_logout_time = [];
employee2_data_logout_date = [];

difference_time1=[];
difference_time2=[];

mysum1 = datetime.timedelta()
employee1_time = []
zip_object = zip(employee1_data_login_time, employee1_data_logout_time)
for list1_i, list2_i in zip_object:
    (h, m, s) = list1_i, list2_i.split(':')
    d = datetime.timedelta(hours=int(h), minutes=int(m), seconds=int(s))
    mysum1 -= d
    employee1_time.append(list1_i-list2_i)

mysum2 = datetime.timedelta()
employee2_time = []
zip_object = zip(employee1_data_login_time, employee1_data_logout_time)
for list3_i, list4_i in zip_object:
    (h, m, s) = list3_i, list4_i.split(':')
    d = datetime.timedelta(hours=int(h), minutes=int(m), seconds=int(s))
    mysum2 -= d
    employee2_time.append(list3_i-list4_i)
    

mysum1 = datetime.timedelta()
for i in employee1_time:
    (h, m, s) = i.split(':')
    d = datetime.timedelta(hours=int(h), minutes=int(m), seconds=int(s))
    mysum1 += d

mysum2 = datetime.timedelta()
for i in employee2_time:
    (h, m, s) = i.split(':')
    d = datetime.timedelta(hours=int(h), minutes=int(m), seconds=int(s))
    mysum2 += d

for i in employee1_time:
    (h, m, s) = i.split(':')
    result1=int(h) * 3600 + int(m) * 60 + int(s);

for i in employee2_time:
    (h, m, s) = i.split(':')
    result2=int(h) * 3600 + int(m) * 60 + int(s);

employee1_wage=result1*wage_per_hour
employee2_wage=result2*wage_per_hour

python

authentication

time

split

calculator

0 Answers

Your Answer

Accepted video resources