f = open(self.name + “.txt”,“a”)
光圈大小:f/1.8-f/2.8大光圈可创造浅景深,f/16-f/22小光圈适合大景深 #生活知识# #摄影技巧# #摄影设备推荐#
题目出处:Vamei http://www.cnblogs.com/vamei
1.
写一个程序,判断2008年是否是闰年。
写一个程序,用于计算2008年10月1日是这一年的第几天?(2008年1月1日是这一年的第一天)
这些小题目是为了方便大家加深对Python理解而设计的。
def isLeapYear(year):
if (year % 400 == 0) or (year % 100 != 0 and year % 4 == 0):
return True
else:
return False
def countDay(year,month,day):
Month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if isLeapYear(year):
Month[1]=29
Day = sum(Month[0:month]) - Month[month-1] + day
return Day
print isLeapYear(2000),countDay(2000,9,9)
print countDay(*[2001,5,1])
python
运行
输出结果为:
True 253
121
2.
有一个record.txt的文档,内容如下:
# name, age, score Tom, 12, 86 Lee, 15, 99 Lucy, 11, 58 Joseph, 19, 56
plain
第一栏为姓名(name),第二栏为年纪(age),第三栏为得分(score)
现在,写一个Python程序,
1)读取文件
2)打印如下结果:
得分低于60的人都有谁?
谁的名字以L开头?
所有人的总分是多少?
3)姓名的首字母需要大写,该record.txt是否符合此要求? 如何纠正错误的地方?
class student(object):
def __init__(self, name, age, score):
super(student, self).__init__()
self.name = name
self.age = age
self.score = score
f = open('record.txt', 'r')
students = []
for content in f :
if not content.startswith('#'):
if not content.isspace():
line = content.strip().split(', ')
s = student(line[0], line[1], int(line[2] ))
students.append(s)
f.close()
for s in students:
if s.score < 60:
print s.name, s.age, s.score
for s in students:
if s.name.startswith('L'):
print s.name, s.age, s.score
total_score = 0
for s in students:
total_score += s.score
print total_score
wrong_name = []
for s in students:
if not s.name.istitle():
wrong_name.append(s.name)
print 'the wrong data :', s.name, s.age, s.score
def modify():
fr = open('record.txt', 'r')
line = []
for content in fr:
if not content.startswith('#'):
if content.islower():
content = content[0].upper() + content[1:]
line.append(content)
fr.close()
fw = open('record.txt', 'w')
fw.write(''.join(line))
fw.close()
modify()
python
运行
网址:f = open(self.name + “.txt”,“a”) https://www.yuejiaxmz.com/news/view/971474
相关内容
python数据分析之读写txt文件集合A满足条件:若a∈A,则f(a)=2a/(2a+1)∈A,f(f(a))∈A,f(f(f(a)))∈A…集合A满足条件:若a∈A,则f(a)=2a/(2a+1)∈A,f(f(a))∈A,f(f(f(a)))∈A,……,以此类推.是否
python3读取文件和异常处理(七)
with open(csv
f(x),g(x)在[a,b]上连续,在(a,b)内可导,且f(a)=f(b)=
设f(x)为[一a,a]上的连续偶函数,且f(x)>0,令 F(x)=∫
设a>0,函数f(x)=x2+a
数学已知f(x)=loga(a^x
python的print(flush=True)实现动态loading......效果
日常电脑操作小技能篇(生活无处不精彩)