高级编程技术第十次作业

10-2 C语言学习笔记

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"))

learning_python.txt

In Python you can store as much information as you want.
In Python you can connect pieces of information.
In Python you can model real-world situations.

10-4 访客名单

file_name = "guest_book.txt"
while 1:
	print("Please enter your name, enter 'exit' to exit")
	name = input()
	if name == 'exit':
		break
	else:
		print(name.title() + ", welcome!")
		with open(file_name, 'a') as f:
			f.write(name.title() + " has visited.\n")

guest_book.txt

Tom has visited.
Jim has visited.
Kessef has visited.

10-6 加法运算

try:
	x = input("Please enter a number:")
	x = int(x)
	y = input("Please enter another number:")
	y = int(y)
except ValueError:
	print("Sorry it is not a number")
else:
	sum = x + y
	print("The sum is: " + str(sum))

10-11 喜欢的数字

favorite_number_write.py

import json

file_name = "favorite_number.json"
number = input("Please input your favorite number: ")
with open(file_name, 'w') as f:
    json.dump(number, f)

favorite_number_read.py

import json

file_name = "favorite_number.json"
with open(file_name) as f:
    number = json.load(f)
    print("I know your favorite number! It's " + str(number))


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值