Skip to content
← Back to Community
How to make an input create a variable
Profile icon
Ferris

I want to be able to create new variables without having to go into the code is there any way to do this

Voters
Profile icon
ElijahBalmore
Profile icon
HasanKhan22
Profile icon
123fdsa
Profile icon
Rodrigo03543
Profile icon
CadenTousley
Profile icon
NADIAISLAM1
Profile icon
DarjheGunasekar
Profile icon
Emilio-XavierXa
Profile icon
Miguelngelnge97
Profile icon
JeremiahApplew1
Comments
hotnewtop
Profile icon
LeonDoesCode

If you are using Python like mentioned in the comments, you can use a dictionary to do this. To create the variables, you can use a function like:

# To store all of your variables allvars = {} # Adds a variable name and value of each variable def addvar(name, val): allvars[name] = val

You can then access your variables from the dictionary, like so:

# Loop through all the keys and valuses in the dictionary for name, val in allvars.items(): # Print the name fo the variable and it's value print(f"{name}:{val}")

Hope this is what you were looking for.

Profile icon
Giothecoder

Show us an example, please. I don’t think it is but, just try and show us an example first.

Profile icon
Giothecoder

Hey guys, isn’t there some weird scoping with var in js that would allow something like this?

Profile icon
AlexanderBirabe

Considering your profile says you code in python, I think you're looking for:

variableName = input("prompt")

The variable 'variableName' gets set to a string of what the user types in (they have to hit enter to submit). You can replace 'prompt' with whatever you want the input prompt to be.

Profile icon
theangryepicbanana

What language are you using?