Skip to content
Sign upLog in
← Back to Community

How to add a input in python

Profile icon
AmalinaJamil

I don't know how to add an input in python because i'm a beginner.
please help

Voters
Profile icon
SamBurnhams
Profile icon
PranavSaravana3
Profile icon
vedikabajp
Profile icon
ModernSonicEXE
Profile icon
ZachariahHiggin
Profile icon
YAHIRAGARNER
Profile icon
Jess0708
Profile icon
C-HH
Profile icon
jrjamir
Profile icon
AmalinaJamil
Comments
hotnewtop
Profile icon
Muffinlavania

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:

print(Your_Variable)

Or add text before it, and add a plus sign then your variable
Like this:
print("The Answer to my question was"+Your_Variable)

Profile icon
UniqueOstrich18

You can use the input() statement:

name = input("Hello! What is your name? ") print("Hello,",name)

If this was helpful, please mark it as the answer.

Profile icon
Kitty118

name = input ("How old are you" name) how do I get it to work....

Profile icon
sheepx

doesnt help

Profile icon
Kitty118

Also,
UniqueOstrich18 is right

Profile icon
multicoder2021

You can also do:

inpute = input('What is your name?') print('You r %a years old' % age)
Profile icon
multicoder2021

Everyone's given the solution, mark at least one as the answer...

It's simple:

name = input('What is your name? ')

Or, if you want to use Python 2,

g = raw_input("Enter your name : ") print g

You can also add a 'str()' or 'int()' to specify what data type is allowed:

name = str(input('Name? ')) age = int(input('Age? '))

It will give an error if you type the wrong data type (integer or string)

Profile icon
multicoder2021

Exactly what both of them said, use the input() function.
You can also specify if it can be an integer or string
Example:

number = int(input("Enter a number: ")) print("The number is : " + number) string = str(input("Enter a string: ") print("You entered '" + 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():

x = int(input("Enter an integer:")) print("The number is {}".format(x))

Example of f-strings [I prefer this method]:

x = int(input("Enter an integer") print(f" The number is {x}")