easygui课后题的最后一道题,我用的笨办法结果全是0,可以帮我指出问题在哪里吗
import easygui as gimport os
code_type=['.py','.c','.cpp','.pas','.asm']
countc=countcpp=countpas=countasm=countpy=0
numpy=numc=numcpp=numasm=numpas=0
num_file=
num_line=
def find_code():
all_file=os.listdir('.')
for each_file in all_file:
if os.path.isfile(each_file):
if os.path.splitext(each_file)==code_type:
global numpy
numpy+=1
with open(each_file,encoding='utf-8') as f:
for each_line in f:
global countpy
countpy+=1
if os.path.splitext(each_file)==code_type:
global numc
numc+=1
with open(each_file,encoding='utf-8') as f:
for each_line in f:
global countc
countc+=1
if os.path.splitext(each_file)==code_type:
global numcpp
numcpp+=1
with open(each_file,encoding='utf-8') as f:
for each_line in f:
global countcpp
countcpp+=1
if os.path.splitext(each_file)==code_type:
global numpas
numpas+=1
with open(each_file,encoding='utf-8') as f:
for each_line in f:
global countpas
countpas+=1
if os.path.splitext(each_file)==code_type:
global numasm
numasm+=1
with open(each_file,encoding='utf-8') as f:
for each_line in f:
global countasm
countasm+=1
if os.path.isdir(each_file):
os.chdir(each_file)
find_code()
os.chdir(os.pardir)
g.msgbox('请打开你存放代码的文件夹')
path=g.diropenbox('请选择你存放代码的文件夹')
os.chdir(path)
find_code()
for each in num_line:
sum=0+each
spare=100000-sum
proportion=sum/100000
msg='您目前共累计编写了%d条代码,完成进度:%.2f\n离十万行代码还差%d行,请继续努力'%(sum,proportion,spare)
title='统计结果'
text=''
for i in range(5):
text+='%s源文件%d个,原代码%d行/n'%(code_type,num_file,num_line)
g.textbox(msg,title,text)
问题出在这:
num_file=
num_line=
你把变量放进去,传递的只是值
也就是说,你对那些变量进行操作是不会改变列表里的值的。
你可以直接改变列表的值,不用变量。
页:
[1]