How to add a input in python
I don't know how to add an input in python because i'm a beginner.
Use @UniqueOstrich18 for the answer, but just use input() like he said
Put whatever variable you want before it, and in the paraenthesis, put what you want to ask in quotes, like this:
Your_Variable = input("Ask your Question Here")
Then you can call this variable later like @UniqueOstrich18 said,
You just either print it like this:
Or add text before it, and add a plus sign then your variable
print("The Answer to my question was"+Your_Variable)
Everyone's given the solution, mark at least one as the answer...
Or, if you want to use Python 2,
You can also add a '
str()' or '
int()' to specify what data type is allowed:
It will give an error if you type the wrong data type (
Exactly what both of them said, use the input() function.
You can also specify if it can be an integer or string
Also, a suggestion:
Instead of printing the variable directly, or doing it like this:
print("TEXT" , variable_name)
You can use the .format() method or use f-strings.
Example of the .format():
Example of f-strings [I prefer this method]: