10-1至10-13
2018-04-05 18:13
239 查看
10-1,Python学习笔记
10-2,C语言学习笔记
10-3,访客
10-4,访客名单
10-6,加法运算
10-7,加法计算器
10-8,猫和狗
10-9,沉默的猫和狗
10-12,记住喜欢的数字
file_name = 'text.txt' with open(file_name) as file_object: contents = file_object.read() print(contents) with open(file_name) as file_object: for line in file_object: print(line.rstrip()) with open(file_name) as file_object: lines = file_object.readlines() for line in lines: print(line.rstrip())
10-2,C语言学习笔记
file_name = 'text.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' name = input("What's your name?") with open(file_name, 'w') as file_object: file_object.write(name)
10-4,访客名单
file_name = 'guest.txt' while 1: name = input("What's your name?") if name == 'q': break with open(file_name, 'a') as file_object: file_object.write(name)
10-6,加法运算
try: x = input('write down a number') y = input('write dow another number') print('the sum is ' + str(int(x) + int(y))) except ValueError: print('sorry, please write down a number.')
10-7,加法计算器
while 1: try: x = input('write down a number') if x == 'q': break y = input('write dow another number') if y == 'q': break print('the sum is ' + str(int(x) + int(y))) except ValueError: print('sorry, please write down a number.')
10-8,猫和狗
file_name = 'cats.txt' try: print("cats' name:") with open(file_name) as file_object: for line in file_object: print(line.rstrip()) except FileNotFoundError: print('sorry, there is not file ' + file_name) file_name = 'dogs.txt' try: print("dogs' name:") with open(file_name) as file_object: for line in file_object: print(line.rstrip()) except FileNotFoundError: print('sorry, there is not file ' + file_name)
10-9,沉默的猫和狗
file_name = 'cats.txt' try: print("cats' name:") with open(file_name) as file_object: for line in file_object: print(line.rstrip()) except FileNotFoundError: print('sorry, there is not file ' + file_name) file_name = 'dogs.txt' try: print("dogs' name:") with open(file_name) as file_object: for line in file_object: print(line.rstrip()) except FileNotFoundError: pass
10-12,记住喜欢的数字
import json file_name = 'save.json' try: with open(file_name) as file_object: num = json.load(file_object) print("I know your favorite number! It's " + str(num)) except FileNotFoundError: number = input("What's your favorite number?") with open(file_name, 'w') as file_object: json.dump(number, file_object)
相关文章推荐
- myeclipse10或myeclipse13激活文件和激活步骤
- ASCII码 char(9),char(10),char(13)
- ASCII码对应表chr(9),char(10),char(13),char(34)等
- 10-12&&10-13总结
- chr(13)和chr(10)
- Java Script基础10-13笔记
- 2012,10,13(ICPC长春赛区热身)
- Eclipse零起步(转)(10~13)
- 学习笔记10-13
- VS低版本打开高版本解决方案(如08打开10、12、13版本vs编译的项目)
- ASCII码对应表chr(9)、chr(10)、chr(13)、chr(32)、chr(34)、chr(39)、chr(42)
- /*请高手指点:C#中得到一串数字中有连续数字的开始和结束位置?比方说0,2,5,6,7,10,12,13,15,18……中,就有5,6,7和12,13两组连续(或更多),则要得到5,6,7的始末位置
- 1,2,3,5,7,8,10,11,12,13,14,15,16,21,22 -》1~3,5,7~8,10~16,21~22
- ASCII码对应表chr(9)、chr(10)、chr(13)、chr(32)、chr(34)、chr(39)、chr(..
- ASCII码对应表chr(9)、chr(10)、chr(13)、chr(32)、chr(34)...
- today-13/10/2007
- 剑指Offer题目:从扑克牌中随机抽 5 张牌,判断是不是顺子,即这 5 张牌是不是连续的。 2-10 为数字本身,A 为 1,J 为 11,Q 为 12,K 为 13,而大小王可以看成任意的 数字。
- 有一个整数n,写一个函数f(n),返回0~n之间出现的“1”的个数,例如f(1)=1; f(13)=6(1,10,11,12,13一共6个1),最大的f(n)=n的n是多少
- APUE读书笔记-10信号-13sigpending函数
- ffmpeg-20160908[09,10,13,15,19,21,22,24]-bin.7z