作者:偶说撒浪嘿 | 来源:互联网 | 2024-10-10 14:31
后端开发|Python教程python笔试题后端开发-Python教程hmtl源码,ubuntu怎么编辑文件,远程访问阿里云tomcat,爬虫得物,vue动态路由php,百度竞价数
后端开发|Python教程
python笔试题
后端开发-Python教程
hmtl源码,ubuntu怎么编辑文件,远程访问阿里云tomcat,爬虫 得物,vue 动态路由php,百度竞价数据分析seo公司lzw
下面这段代码:
2017个人博客源码,vscode调试完成后,ubuntu yum 版本,tomcat猫出不来,爬虫没有request,php 验证码技术,保定seo优化大概多少费用,php 导航网站 自动收录,简单自适应单页模板lzw
# name, age, scoretom, 12, 86Lee, 15, 99Lucy, 11, 58Joseph, 19, 56
第一栏为姓名(name),第二栏为年纪(age),第三栏为得分(score)
php搭建小说网站源码,ubuntu自动重启进程,多网页抓取爬虫,外研社php,刷排名 seolzw
现在,写一个Python程序,
1)读取文件
2)打印如下结果:
得分低于60的人都有谁?
谁的名字以L开头?
所有人的总分是多少?
3)姓名的首字母需要大写,该record.txt是否符合此要求? 如何纠正错误的地方?
#read lines from filefobj = open('record.txt', 'r+')print 'opened file: ', fobj.nameall_lines = fobj.readlines()fobj.close()lines = [l[:-1].split(', ') for l in all_lines if not l.startswith('#') and l.strip()]#list person who's score less than 60print [s[0] for s in lines if int(s[2]) <60]#list person who&#039;s name starts with &#039;L&#039;print [s[0] for s in lines if s[0].startswith(&#039;L&#039;)]#compute the score of all personprint sum([int(s[2]) for s in lines])#write new lines contains capitalize name into filefobj = open(&#039;record2.txt&#039;, &#039;w+&#039;)print &#039;opend file: &#039;, fobj.namenewlines = []for line in all_lines: if line[0].islower(): line = line.capitalize() newlines.append(line)print newlinesif newlines: fobj.writelines(newlines)fobj.close()