py第十章习题

#10-6
a = input('Please input two numbers.')
b = input()
try:
	a = int(a)
	b = int(b)
	re = a + b
except ValueError:
	print('Please input number.')
else:
	print(str(a) + ' + ' + str(b) + ' = ' + str(re))

#10-7
flag = 0
while flag == 0:
	a = input('Please input two numbers.')
	b = input()
	try:
		a = int(a)
		b = int(b)
		re = a + b
	except ValueError:
		print('Please input number.')
	else:
		print(str(a) + ' + ' + str(b) + ' = ' + str(re))
		flag = 1


#10-2message = 'Hello, my friend'print(message)message.replace('friend', 'partner')print(message)#10-3filename = 'guest.txt'with open(filename, 'a') as f_ob:i = input('Enter your name:')f_ob.write(i)#10-4filename = 'guesst_book.txt'with open(filename, 'a') as f:t = input('Enter your name: (input "exit" to exit)')while(t != 'exit'):print('Welcome! ' + t)f.write(t + '\n')t = input('Enter your name:')#10-5filename = 'reason.txt'with open(filename, 'a') as f:t = input('Why do you like programming? (input "exit" to exit)')while(t != 'exit'):print('We got it.')f.write(t + '\n')t = input('Why do you like programming? (input "exit" to exit)')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值