第五周作业(2)——高级编程技术
2018-04-08 22:26
316 查看
一、第十章作业节选
10-1
with open('learning_python.txt') as file_object:
contents = file_object.read()
print(contents)
print("\n")
fileName = 'learning_python.txt'
with open(fileName) as file_object:
for line in file_object:
print(line.rstrip())
print("\n")
file_name = 'learning_python.txt'
with open(file_name) as file_object:
lines = file_object.readlines()
for line in lines:
print(line.rstrip())
![](https://img-blog.csdn.net/20180408214254199)
10-2
file_name = 'learning_python.txt'
with open(file_name) as file_object:
lines = file_object.readlines()
for line in lines:
print(line.replace('Python', 'C').rstrip())
![](https://img-blog.csdn.net/20180408215112591?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3lhbmdsaWp1bjJf/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
10-3
file_name = 'guest.txt'
with open(file_name, 'w') as file_object:
name = input("Please input your name: ")
file_object.write(name)
![](https://img-blog.csdn.net/20180408220025838?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3lhbmdsaWp1bjJf/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
10-4
file_name = 'guest_book.txt'
with open(file_name, 'w') as file_object:
while True:
name = input("Please input your name(you can stop by typing quit): ")
if name == 'quit':
break
else:
print(name + ", nice to meet you.\n")
name += ", recorded.\n"
file_object.write(name)
![](https://img-blog.csdn.net/20180408221313217?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3lhbmdsaWp1bjJf/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
10-5
file_name = 'reasons.txt'
with open(file_name, 'a') as file_object:
while True:
reason = input("Please input your reason for love grogramming(you can stop by typing quit):\n")
if reason == 'quit':
break
else:
file_object.write("\n")
reason += "\n"
file_object.write(reason)
![](https://img-blog.csdn.net/20180408222445307?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3lhbmdsaWp1bjJf/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
10-1
with open('learning_python.txt') as file_object:
contents = file_object.read()
print(contents)
print("\n")
fileName = 'learning_python.txt'
with open(fileName) as file_object:
for line in file_object:
print(line.rstrip())
print("\n")
file_name = 'learning_python.txt'
with open(file_name) as file_object:
lines = file_object.readlines()
for line in lines:
print(line.rstrip())
10-2
file_name = 'learning_python.txt'
with open(file_name) as file_object:
lines = file_object.readlines()
for line in lines:
print(line.replace('Python', 'C').rstrip())
10-3
file_name = 'guest.txt'
with open(file_name, 'w') as file_object:
name = input("Please input your name: ")
file_object.write(name)
10-4
file_name = 'guest_book.txt'
with open(file_name, 'w') as file_object:
while True:
name = input("Please input your name(you can stop by typing quit): ")
if name == 'quit':
break
else:
print(name + ", nice to meet you.\n")
name += ", recorded.\n"
file_object.write(name)
10-5
file_name = 'reasons.txt'
with open(file_name, 'a') as file_object:
while True:
reason = input("Please input your reason for love grogramming(you can stop by typing quit):\n")
if reason == 'quit':
break
else:
file_object.write("\n")
reason += "\n"
file_object.write(reason)
相关文章推荐
- 高级编程技术作业第五周 第九章课后练习
- 高级编程技术作业第五周 第十章课后练习
- 第五周作业(1)——高级编程技术
- 高级编程技术 第五周作业
- 【高级编程技术】【作业】【第五周】【1】
- 高级编程技术第五周作业
- 【高级编程技术】第五周作业
- 高级编程技术 Python 第五周作业
- 《高级编程技术》第五周作业
- 佐治亚理工学院 计算投资公开课第五周作业 市场仿真器
- 高级编程技术第一周平时作业
- 高级编程技术作业_3
- 菜鸟之路【计算导论与C基础】练习1 计算概论第五周 B-04作业
- 第三周作业(1)——高级编程技术
- 高级编程技术第三周平时作业
- 9.27第五周java作业
- 高级编程技术(Python)作业6
- 高级编程技术第五、六次作业
- 高级编程技术第七次作业
- 高级编程技术作业_9