Traceback (most recent call last):
File "./test.py", line 6, in <module>
my_string = input(" :")
File "<string>", line 1, in <module>
NameError: name 'hello' is not defined
Please mention the Python version you're using.
Since the difference between your two programs is the "input()" function, it should be clear that the "input()" function is the problem.
So, when you enter "hello" at the prompt, Python tries to evaluate it and throws an error since it is an undefined identifier.
$
$ cat -n test.py
1 my_string = input(": ")
2 my_string = str(my_string)
3
4 if len(my_string) < "6":
5 print(my_string + " < 6")
6 else:
7 print(my_string + " > 6")
8
$
$ python --version
Python 2.5.1
$
$ python ./test.py
: hello
Traceback (most recent call last):
File "./test.py", line 1, in <module>
my_string = input(": ")
File "<string>", line 1, in <module>
NameError: name 'hello' is not defined
$
$
If you really want to use the "input()" function, enter an expression that could be evaluated by "eval()" and you will not see the error message.
$
$ python ./test.py
: 2 + 3
5 < 6
$
$
In the above execution, I entered "2 + 3" which was evaluated by "eval()" to obtain 5. That was converted to string and assigned to "my_string" and then the comparison works.