-3

I'm trying to get user input on something but it's not very user friendly to have to put quotations each time you type an answer.

    loop = True
    while loop:

        user_input = input("say hello \n")
        if user_input == "hello":
        print("True")

I want to be able to just type hello and not have to add the quotations (ex. "hello").

Asori12
  • 133
  • 1
  • 14

2 Answers2

1

In the Python 3.6 interactive prompt:

>>> user_input = input("say hello \n")
say hello 
hello
>>> user_input
'hello'

you need to quote the string when you check equality, but shouldn't need to for the input. as others have said, in python 2.x, use raw_input. Python 2.7:

>>> user_input = raw_input("say hello \n")
say hello 
hello
>>> user_input
'hello'
Jason Stein
  • 714
  • 3
  • 10
0

There is a slight difference in between input and raw_input: What's the difference between raw_input() and input() in python3.x?

python 2.7:

loop = True
hello_input = "hello"
while loop:
    user_input = raw_input("say hello \n")
    if user_input == hello_input:
        print("True")

python 3:

loop = True
hello_input = "hello"
while loop:
    user_input = input("say hello \n")
    if user_input == hello_input:
        print("True")

When you run these programs you wont have to put input in terminal with quotes:

eg:

say hello
hello
True
Vikash Singh
  • 13,213
  • 8
  • 40
  • 70
  • 1
    If you think a question is a duplicate then you should flag it as such, as written, there is no way to know if this really is the issue. – Sayse Aug 02 '17 at 14:15
  • 1
    @Sayse The question is not a duplicate because the Asker does not know that what he/she is looking for is a different approach for the same problem. ie: use `raw_input` instead of `input`. – Vikash Singh Aug 02 '17 at 14:19