what should i do for save list that i listed in my code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

what should i do for save list that i listed in my code

#python i wrote this code and when i start it,it want's input until you write (finish). if i want to save this list and then when i want append some another items in it start and append my items what should i do? use simple words pls , eng is not my mother lang books_list = [] print("when your books list finish,type 'finish' ") x = str() while x != "finish": x = str(input("please enter your book name:")) books_list.append(x) if x=="finish": print(books_list) x = str(len(books_list)) print("you have " + x + " books" )

1st Apr 2022, 4:52 PM
Mohammad Ali Akbarzadeh
Mohammad Ali Akbarzadeh - avatar
5 Answers
+ 3
books_list=[] while True: x = str(input("please enter your book name:")) books_list.append(x) if x=="finish": print(" ".join(books_list)) x = str(len(books_list)) print("you have " + x + " books" ) print("when your books list finish,type 'finish' ") break
2nd Apr 2022, 12:42 AM
CodeStory
CodeStory - avatar
+ 2
Alphonse , there is a python module named 'pickle', that can serialize python objects and write it to a file. later on, the object can be read from the file and used in your code. see my sample. if you try it, please make sure that the sample file is stored physically before you use it. https://code.sololearn.com/c97mYZtEvGO0/?ref=app
1st Apr 2022, 5:48 PM
Lothar
Lothar - avatar
+ 2
Please do remember when using Sololearn playground, don't add a prompt message to input(), use input() and not input("enter your name: ")
3rd Apr 2022, 11:33 AM
Demiz 🇬🇭🇬🇭🇱🇷🇱🇷
Demiz 🇬🇭🇬🇭🇱🇷🇱🇷 - avatar
+ 1
CodeStory you're adding "finish" to the list as well which is not a book's name, Alphonse your if - statement is not necessary as the block of code is outside the while loop, the code gives error because of your infinite loop eg. x = str() , so while x != "finish" is infinitely considered True as x value will not change, I added nothing else, just reformat your code https://code.sololearn.com/cDxeAipQoI0p/?ref=app
3rd Apr 2022, 11:29 AM
Demiz 🇬🇭🇬🇭🇱🇷🇱🇷
Demiz 🇬🇭🇬🇭🇱🇷🇱🇷 - avatar
0
I don’t know exactly But you have to save your output as a file. Then next time open the file.
1st Apr 2022, 5:01 PM
Beh
Beh - avatar