Skip to content
Advertisement

read and return text file with def function

i want to input the file name in this case books.txt and get the lines but i cant get it work, i have the files in the same directory but when i run this nothing happens, any way to fix this? or to call that function in another .py file

JavaScript
JavaScript

but this return nothing and i dont know what to do :(

Advertisement

Answer

You need to add this line to the end, so it actually prints out the values:

JavaScript

So the full code would be (I also changed some code as the OP said what to change):

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement