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()
------------恢复内容结束------------