Small Python jobs

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.