I worked with Python to print the ALE.txt
file in the picture like output.txt
, but it's blocked to some extent. Can you help me?
I made it roughly, but I don't know what to do from here.I don't know if that's right.
infile1=open("ALE.txt","r")
infile2=open("output.txt","w")
str1="Team\t\twon\t\tlost\t\tpercentage"
infile2.write(str1)
for line in infile1:
list=line.split(",")
Is it hard to get a percentage?
round(won/(won+lost), 3)
You can do it.
Is the next song called "sort"?
In [1]: L = [('a', 3), ('b', 2), ('c', 1)]
In [2]: from operator import itemgetter
In [3]: L.sort(key=itemgetter(1))
In [4]: L
Out[8]: [('c', 1), ('b', 2), ('a', 3)]
Please refer to the code below Please code it simpler and share it with me...
f = open('c:/Users/USER/Desktop/ALE.txt','r')
s = f.read().split('\n')
f.close()
str1="Team won lost percentage\n"
f2 = open('c:/Users/USER/Desktop/output.txt','w+')
f2.write(str1)
for i in s:
i = i.split(',')
i.append('%0.3f' %(int(i[1])/(int(i[1])+int(i[2]))))
for j in range(len(i)):
i[j] = i[j] + ' '*(12-len(i[j]))
f2.write(i[j])
f2.write('\n')
f2.seek(0)
for k in f2:
print(k)
f2.close()
>>> ==================== RESTART: C:/Users/USER/Desktop/b.py =============
Team won lost percentage
Baltimore 96 66 0.593
Boston 71 91 0.438
New York 84 78 0.519
Tampa Bay 77 85 0.475
Toronto 83 79 0.512
© 2025 OneMinuteCode. All rights reserved.