Cjupyter Untitled27 Last Checkpoint: 2 hours ago (unsaved chang- aaa Notepad Fil
ID: 3725321 • Letter: C
Question
Cjupyter Untitled27 Last Checkpoint: 2 hours ago (unsaved chang- aaa Notepad File Edit Format View Help est a line 1 line 2 line 3 File Edit View nsert Cell Kenel Widgets Help a rest In [11: def open function (P): open (P, 'r') first_line-f.readline() rest = f.readlines() return first line, rest f.close In [3]: first_line, rest-open_function('bbb.txt') rest-b rest first_line, rest-open_function( 'aaa.txt') rest-a rest print (a_rest) print (b rest) bbb - Notepad File Edit Format View Help NameError ipython-input-3-8e6377ebaa79 line 2 line 3 in module() 1 first_line, rest-open_function ("bbb.txt') b rest line 4 - 2 rest-b_rest 4 first_line, rest-open_function('aaa.txt) 5 rest-a rest NameError: name 'b_rest' is not defined O Type here to search i would like to print a rest and b rest at will by just typing print(a _rest) how can i do this?Explanation / Answer
I am giving program which is error free and is output is as expected
def open_function(P):
f=open(P,'r')
first_line=f.readline()
rest=f.readlines()
rest=[i.strip() for i in rest]
f.close()
return first_line,rest
first_line,b_rest=open_function('bbb.txt')
first_line,a_rest=open_function('aaa.txt')
a_rest=a_rest+b_rest
print(a_rest)