+ 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" )
6 Antworten
+ 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
+ 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
+ 2
Please do remember when using Sololearn playground, don't add a prompt message to input(), use input() and not input("enter your name: ")
+ 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
0
I don’t know exactly
But you have to save your output as a file. Then next time open the file.