I thought the input
method will take any numeric or string input and print it out. But for string
it does not work unless string
is in quoted. Why?
Asked
Active
Viewed 693 times
0

saeed foroughi
- 1,662
- 1
- 13
- 25

webiondev
- 135
- 1
- 7
-
Please post the code as text not images – U13-Forward Feb 18 '20 at 02:24
-
in what environment are you trying this? – saeed foroughi Feb 18 '20 at 02:28
-
Does this answer your question? [input() error - NameError: name '...' is not defined](https://stackoverflow.com/questions/21122540/input-error-nameerror-name-is-not-defined) – user202729 Dec 30 '21 at 14:21
2 Answers
2
In Python 2.7, input()
evaluates the input as code, so strings need to be quoted. Python 2.7 has a method called raw_input()
that treats all input as strings (no quotes needed).
In Python 3.x, the Python 2.7 raw_input()
method was renamed input()
and the Python 2.7 input()
functionality was replaced by eval(input())
So you can use raw_input()
in Python 2.7 or switch to Python 3.x

saeed foroughi
- 1,662
- 1
- 13
- 25
0
Make sure that you are running the code on Python 3 and not Python 2. On python 2 you are needed to quote your input with ""
it seems like there are multiple solution to this though:

Kenta Nomoto
- 839
- 6
- 11