Skip to content
Sign upLog in
← 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
EthanBiedenstei
Profile icon
SwarnabRoy
Profile icon
EmileeTaitt
Profile icon
ElijahBalmore
Profile icon
HasanKhan22
Profile icon
123fdsa
Profile icon
Rodrigo03543
Profile icon
CadenTousley
Profile icon
NADIAISLAM1
Profile icon
DarjheGunasekar
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
jasminvancet82
Profile icon
TannerTommy

Wonderful blog post, resolved to go on and even bookmarked your webblog. As i can’t hold on to enjoy a book alot more as a result of one.
homes for sale in rochester hills mi

Profile icon
TannerTommy

This is an alternative to using Ethernet for the connection between your device and the router. A free WiFi network is what you get when you install a router; pocket wifi rental there’s only one upfront cost for the router, unless someone will give you an old router they no longer use.

Profile icon
TannerTommy

I have no idea how does an input creates a variable. Though I am sure you'll find content about it on https://www.paisley.org.uk/2022/01/how-to-find-the-best-uk-essay-writing-service/. Make sure to check it out once.

image

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?