Skip to content
Sign upLog in
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
23

How to make an input create a variable

Ferris
Ferris

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

3 years ago

Voters

Comments

TopNew
4
LeonDoesCode
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.

3 years ago
2
Giothecoder
Giothecoder

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

3 years ago
1
TannerTommy
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

3 months ago
1
TannerTommy
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.

3 months ago
1
TannerTommy
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

4 months ago
1
Giothecoder
Giothecoder

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

3 years ago
1
AlexanderBirabe
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.

3 years ago
1
theangryepicbanana
theangryepicbanana

What language are you using?

3 years ago
Load more