Hello, guys. I’m new to Python, and I’m currently working on a program. In this program, I need to create a function to add a new column for drivers. However, I’m not sure how to do this correctly. I attempted to use a standard list and the ‘append’ function, but it only works once. When I try to add another entry, the program doesn’t recognize what I entered previously. I hope I have explained the problem clearly, and I would appreciate your help.
Yep, you’ve explained the problem, but it would help us a lot if we could also see your code. Paste it in here, then select it and select the
</> button on the toolbar, which will make it into a preformatted code block.
Okay, when I’ll back home, I’ll send you part of my code, with comments, that you can understand what I talking about.
#importing time to using sleep import time #my list of users, which when I need i selected list_of_reg_num = ['Alexander Pushkin, Mikhail Lermontov, Leo Tolstoy'] #Input which allows you to enter in "adding mode" sel_num = input("Select a driver from the list: " + str(list_of_reg_num) + "\nTo go to Add New User mode, type "Add New User" (small letter is fine). ") time.sleep(0.5) #function which created to help add new user in list def add_new_user(): if sel_num.lower() == "Add a new user": print("You are now in add new user mode...") time.sleep(1) back = input("To cancel this action, simply press Enter. \If you do want to add a new user, type "Add" (lowercase letters are allowed). ") if back == "": print("The program will now complete its work...") time.sleep(1) exit() #If user complete all of this checks, and he really want to adding a new user, program are request a first name and the last name. elif back.lower() == "add": new_value = input("Enter the first name and last name of the user you want to add: ") save = input("Save the result? ") #if users entered "yes", program are adding new value to my list_of_red_num, but this is for one time, when program are closing values doesn't save. if save.lower() == "да": list_of_reg_num.append(new_value) print(list_of_reg_num) print("The program will restart with the new data...") time.sleep(1) exit()
I hope this could help you, below you can check what is displayed in the terminal
Choose a driver from the list: ['Alexander Pushkin', 'Mikhail Lermontov', 'Leo Tolstoy'] To go to the mode of adding a new user write "Add new user" (can be with a small letter) Add new user Now you have gone to add a new user... To cancel this action just press "Enter". If you want to add a new user just type in Add. Enter user name you wish to add: Vladislav Ivanov Will you save the result? ['Alexander Pushkin', 'Mikhail Lermontov', 'Leo Tolstoy', 'Vladislav Ivanov'] The program will restart with the new data...
At what point does the program actually restart with the new data? Currently it just exits.
I tried this, but program is adding a new values one time and she close. But I don’t know which command are help me, to save this list with a new parameters.
The code that I see as I’m writing this has syntax errors, and when fixed, doesn’t produce the given output.