Today, I worked on the zim coding challenge. I still need to work on adding the file.
#xfile=open('mbox-short-short.txt')
#fname=input('enter a file name')
xfile='zimTextFile.txt'
try:
fhand=open(xfile)
except:
print('bad dog... no file found')
quit()
# challenge 1
xfile = open('zimTextFile.txt')
print(xfile)
counterofline=0
counterofchar=0
counterofzim=0
counterofstartswithzim=0
realzimcount=0
for line in xfile:
# challenge 2
counterofline=counterofline+1
# challenge 3
counterofchar=counterofchar+len(line)
# challenge 4.1
if'Zim'in line:
counterofzim=counterofzim+1
#print(line)
# challenge 4.2
if line.startswith('Zim:'):
counterofstartswithzim=counterofstartswithzim+1
line=line.rstrip()
# real challenge 4.1
linelistzim=line.split()
print(linelistzim)
for realzim in linelistzim:
if 'Zim' in realzim:
realzimcount=realzimcount+1
print('line count= ',counterofline)
print('char count= ',counterofchar)
print('Zim count= ',counterofzim,'wait, is that right?')
print('Zim: count= ', counterofstartswithzim)
print('Real Zim: count=',realzimcount)
newFileHandle=open('newFile.txt', 'w')
print(newFileHandle)
newFileHandle.write('line count= ')
counteroflinestr=str(counteroflinestr)
newFileHandle.write(counterofline)
newFileHandle.write('\n')
newFileHandle.close()
No comments:
Post a Comment