1. 程式人生 > 實用技巧 >第一次封裝軟體

第一次封裝軟體

import xlrd
from xlutils.copy import copy


def data_operate():
filename = input('請放入檔案:')
text = xlrd.open_workbook(filename)
sht = text.sheets()[0]
order = 3
difference = (sum([sht.cell(i, 2).value for i in range(3)])-sum([sht.cell(i, 0).value for i in range(3)]))/ 3
lst2 = []
new_sheet = copy(text)
ws = new_sheet.get_sheet(0)
try:
for t in range(2, int(input('請輸入資料行數:')) // 3 + 1):
lst = []
for i in range((t-1) * 3, t * 3):
lst.append(sht.cell(i, 0).value)
num1 = sum(lst) / 3
for j in range((t-1) * 3, t * 3):
lst2.append(2**(difference - (sht.cell(j, 2).value - num1)))
for i in lst2:
ws.write(order, 4, i)
order += 1
new_sheet.save(filename)
except:
print('您放入的檔案存在問題,請您檢查!')
exit()


def check():
word = input("輸入指令:")
if word == 'T' or word == "t":
pass
elif word == 'F' or word == "f":
exit()
else:
print("你的指令格式不正確,請重新輸入!")
check()


def menu():
while True:
data_operate()
print("上一檔案已處理完畢,是否繼續?(True/False)")
check()


menu()

------------恢復內容開始------------

import xlrd
from xlutils.copy import copy


def data_operate():
filename = input('請放入檔案:')
text = xlrd.open_workbook(filename)
sht = text.sheets()[0]
order = 3
difference = (sum([sht.cell(i, 2).value for i in range(3)])-sum([sht.cell(i, 0).value for i in range(3)]))/ 3
lst2 = []
new_sheet = copy(text)
ws = new_sheet.get_sheet(0)
try:
for t in range(2, int(input('請輸入資料行數:')) // 3 + 1):
lst = []
for i in range((t-1) * 3, t * 3):
lst.append(sht.cell(i, 0).value)
num1 = sum(lst) / 3
for j in range((t-1) * 3, t * 3):
lst2.append(2**(difference - (sht.cell(j, 2).value - num1)))
for i in lst2:
ws.write(order, 4, i)
order += 1
new_sheet.save(filename)
except:
print('您放入的檔案存在問題,請您檢查!')
exit()


def check():
word = input("輸入指令:")
if word == 'T' or word == "t":
pass
elif word == 'F' or word == "f":
exit()
else:
print("你的指令格式不正確,請重新輸入!")
check()


def menu():
while True:
data_operate()
print("上一檔案已處理完畢,是否繼續?(True/False)")
check()


menu()

------------恢復內容結束------------