def fad(n): if n<1: print('报错') return -1 if n == 1 or n == 2: return 1 else: return fad(n-1) + fad(n-2) result = fad(int(input('输入:'))) if result !=-1: print('总数:',result)
def hanoi (n,a,b,c): if n==1: print(a,'>>',c) else: hanoi(n-1,a,c,b) print(a,'>>',c) hanoi(n-1,b,a,c) n = int(input('输入:')) hanoi(n,'a','b','c')
2019-12-230个赞
>>> f = open('E:\\text.txt','w') >>> f.write('fdsljfdsljfldsjfl') 17 >>> f.close() >>>
2019-12-300个赞
def save_file(A,B,count): file_name_A = 'A_'+str(count)+'.txt' file_name_B = 'B_'+str(count)+'.txt' A_file = open(file_name_A,'w') B_file = open(file_name_B,'w') A_file.writelines(A) B_file.writelines(B) A_file.close() B_file.close() def split_file(file_name): f = open('E:\\form.txt') A= [] B= [] count=1 for each_line in f: if each_line[:6] != '=======': (c,d)=each_line.split(':',1) if c=='A': A.append(d) if c=='B': B.append(d) else: save_file(A,B,count) A=[] B=[] count += 1 save_file(A,B,count) f.close() split_file('form.txt')
2019-12-300个赞