码迷,mamicode.com
首页 > 编程语言 > 详细

Python之小作业

时间:2014-05-14 11:41:36      阅读:452      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   java   c   

文档如下:

# name, age, score

tom, 12, 86

Lee, 15, 99

Lucy, 11, 58

Joseph, 19, 56

第一栏为姓名(name),第二栏为年纪(age),第三栏为得分(score)

现在,写一个Python程序,

1)读取文件

2)打印如下结果:

得分低于60的人都有谁?

谁的名字以L开头?

所有人的总分是多少?

3)姓名的首字母需要大写,该record.txt是否符合此要求? 如何纠正错误的地方?

 

本人英文渣渣 代码写了好久也 代码如下:

bubuko.com,布布扣
 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=0
18     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() # 3
25 lessthen60() #2.1)
26 namestartwithL() #2.2)
27 total() #2.3)
bubuko.com,布布扣

本人的环境为 linux + python 3.32 + pycharm 3.1

Python之小作业,布布扣,bubuko.com

Python之小作业

标签:style   blog   class   code   java   c   

原文地址:http://www.cnblogs.com/Concho/p/3726857.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!