Is there a way to create a variable after user input? Multiple ones, rather. For example, I’m writing a simple little program that records what page you’re on in a book, but I’d like it to record as many books as the user needs. So, for example, the program would ask a user how many books they would like to record bookmarks for. If the user inputs 5, it would create 5 randomly named variables, and be able to read them back at a later time. I should be fine writing everything on my own, but I would need to know, is there a way to create a variable from user input, and if so, how?
Share
While you have the right idea, it’s the wrong implementation. Try a
listinstead:And then access them with:
EDIT:
As suggested by a commenter, you could use a
dicttoo. They are useful.This short program will let you input books in the form of
Then use it like:
to access your variable.