import datetime,calendar,random,time
def randomlist(arr):
length = len(arr)
if length < 1:
return ''
if length == 1:
return arr[0]
randomNumber = random.randint(0,length-1)
return int(arr[randomNumber])
def replace(arr):
list=[]
for i in arr:
if i == 0: list.append('休息')
if i == 1: list.append('早班')
if i == 2: list.append('晚班')
return list
def paiban():
start = input("輸入排班開始時間YMD:")
end = input("輸入排班結束時間YMD:")
dayCount = (datetime.datetime.strptime(end, "%Y%m%d") - datetime.datetime.strptime(start, "%Y%m%d")).days
print(dayCount)
monthRange = calendar.monthrange(int(datetime.datetime.now().strftime('%Y')),int(datetime.datetime.now().strftime('%m')))
a1 = [] ;a2 = [];a3 = []
for i in range(1,monthRange[1]+1):
list = [0,1,2]
if i == 1:
b1 = random.randint(0, 2)
list.remove(int(b1))
b2 = randomlist(list)
list.remove(int(b2))
b3 = randomlist(list)
if i == 2:
if a1[0] == 0:
b1 = random.randint(1, 2)
list.remove(b1)
if b1 == a2[0]:
b2 = 0
list.remove(b2)
b3 = randomlist(list)
if a2[0] == 0:
b2 = random.randint(1, 2)
list.remove(b2)
if b2 == a1[0]:
b1 = 0
list.remove(b1)
b3 = randomlist(list)
if a3[0] == 0:
b3 = random.randint(1, 2)
list.remove(b3)
if b3 == a2[0]:b2 = 0
list.remove(b2)
b1 = randomlist(list)
if i >= 3:
if a1[i-2]==0:
if a2[i-2]>0 and a2[i-3]>0:
b1 = a2[i-2]
list.remove(b1)
b2 = 0
list.remove(b2)
b3 = randomlist(list)
else:
b1 = a3[i-2]
b2 = a2[i-2]
b3 = 0
if a2[i - 2] == 0:
if a3[i-2]>0 and a3[i-3]>0:
b2 = a3[i-2]
list.remove(b2)
b3 = 0
list.remove(b3)
b1 = randomlist(list)
else:
b2 = a1[i - 2]
list.remove(b2)
b1 = 0
list.remove(b1)
b3 = randomlist(list)
if a3[i - 2] == 0:
if a1[i-2]>0 and a1[i-3]>0:
b3 = a1[i-2]
list.remove(b3)
b1 = 0
list.remove(b1)
b2 = randomlist(list)
else:
b3 = a2[i - 2]
list.remove(b3)
b2 = 0
list.remove(b2)
b1 = randomlist(list)
a1.append(b1)
a2.append(b2)
a3.append(b3)
YM = datetime.datetime.now().strftime('%Y%m')
print("A員工排班資訊:%s\nB員工排班資訊:%s\nC員工排班資訊:%s" % (replace(a1),replace(a2),replace(a3)))
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/106380.html
上一篇:Python爬圖蟲網站圖片
