The document is as follows:
# Name, age, score
Tom, 12, 86
Lee, 15, 99
Lucy, 11, 58
Joseph, 19, 56
The first column is name, the second column is age, and the third column is score)
Now, write a Python program,
1) read files
2) print the following results:
Who has scored less than 60?
Whose name starts with L?
What is the total score of all people?
3rd, is the record.txt compliant with this requirement? How to correct errors?
I have written the English slag code for a long time and the code is as follows:
1 def isupper(): 2 for i in range(len(userinfo)) : 3 if userinfo[i][0][0].islower() : 4 print('The name is lower : %s '%userinfo[i][0]) 5 print('Right is %s'%userinfo[i][0].capitalize()) 6 def lessthen60(): 7 print('Score less then 60 :') 8 for i in range(len(userinfo)) : 9 if int(userinfo[i][2]) < 60 :10 print(userinfo[i][0])11 def namestartwithL():12 print('Name startwith L :')13 for i in range(len(userinfo)) :14 if userinfo[i][0][0]=='L':15 print(userinfo[i][0])16 def total():17 s=018 for i in range(len(userinfo)) :19 s=s+int(userinfo[i][2])20 print('Total:%s'%s)21 f=open('record.txt','r') #1)22 userinfo=[line.split(', ') for line in f if line[0].isalpha()]23 f.close()24 isupper() # 325 lessthen60() #2.1)26 namestartwithL() #2.2)27 total() #2.3)
My environment is linux + python 3.32 + pycharm 3.1